I want to do a wilcoxson signed rank test out multiple for multiple variables in my dataset at once. I tried a for loop and it did not work so i found a solution with a function but it is giving me a following error/warning. I have a common string "att" in each of my variable name but it seems grep function will not work. I tried multiple ways. The grouping variable is country all the variables beginning with "att" are the ones I want to test against the country variable.
Can someone help me with this? I am attaching sample data and the code I tried.
Thanks you
wil<-structure(list(country = c("Colombia-Bucaramanga", "Colombia-Bucaramanga",
"Colombia-Bucaramanga", "Colombia-Bucaramanga", "Colombia-Bucaramanga"), Fecha_bankssp = c(44422L, 44423L, 44423L, 44423L, 44423L), att1_goodofall = structure(c(4L, 4L, 2L, 4L, 4L), label = "Good of all", class = c("labelled", "integer")), att2_pvtdisease = structure(c(4L, 4L, 3L, 3L, 4L), label = "Helps prevent disease", class = c("labelled", "integer")), att3_curedisease = structure(c(4L, 2L, 4L, 3L, 3L), label = "Helps cure disease", class = c("labelled", "integer")), att4_timewaste = structure(c(4L, 4L, 3L, 5L, 4L), label = "Waste of time", class = c("labelled", "integer")), att5_helpgenerations = structure(c(4L, 4L, 4L, 4L, 3L), label = "Benefits future generations", class = c("labelled","integer")), att6_healthinterfere = structure(c(4L, 3L, 3L, 5L, 3L), label = "Interferes with health", class = c("labelled", "integer")), att7_helpfamily = structure(c(4L, 3L, 3L, 3L, 4L), label = "Helps family", class = c("labelled", "integer")), att8_noriskstolen = structure(c(4L, 2L, 3L, 4L, 2L), label = "Medical information is not stolen", class = c("labelled", "integer")), att9_helpdengue = structure(c(4L, 4L, 4L, 4L, 2L), label = "Advances dengue research", class = c("labelled", "integer")), att10_perinfosafe = structure(c(4L, 4L, 3L, 4L, 2L), label = "Personal information is safe", class = c("labelled", "integer")), att11_identhealthproblem = structure(c(4L, 2L, 3L, 3L, 4L), label = "Helps to identify health problem", class = c("labelled", "integer")), att12_highmedicalcost = structure(c(4L, 3L, 2L, 4L, 3L), label = "Further increases medical costs", class = c("labelled", "integer"))), row.names = c(NA, 5L), class = "data.frame")
modellist<-list(bank)
for(i in bank){
fmla <- formula(paste(names(bank)[i], " ~ country"))
modelList[[i]]<-wilcox.test(fmla, data = bank, paired = FALSE)
}
Warning: Using formula(x) is deprecated when x is a character vector of length > 1.
Consider formula(paste(x, collapse = " ")) instead.Error in terms.formula(formula, data = data) :
invalid term in model formula
Sorry, I just found the answer. I am posting the solution below. I made a silly mistake.