0

So I have a customer survey, and I need to determine if there are significant differences between the four areas. I obviously want to do a t-test on these, and here is my current R solution.

`for (i in colnames(c_survey)) 
assign(i, subset(c_survey, select=i))
elements <- list(quality, ease.of.use, price, service)
elements_alt<-list(service,price,ease.of.use,quality)
for(i in elements){print(names(elements)[i])
for (j in elements_alt) {print(t.test(i,j)$p.value)}}`

(Edit) I figured out the nested loop, but I still think there's a faster way to do what I want than this whole two list, nested loop nonsense. Also my output from this has no names on it so I have no idea what's being compared to what, and it includes all the duplicate inverse comparisons. I also can't save the results. I think my solution certainly lies elsewhere.

Also, would producing so many t-test p values even be the best statistical way to accomplish what I want? It seems like there should be something easier than this...

CapnShanty
  • 529
  • 8
  • 20
  • 1
    Leaving aside the technical issue of how to apply a function to multiple columns/pairs of columns, is it so obvious that you'll want to t-test? Why are you comparing these pairs of variables specifically and why are you comparing them one at a time instead of all at once using an F-test? – RoyalTS Apr 08 '17 at 17:25
  • An f-test probably makes more sense but I didn't want to assume normality. I still just need to see if the survey responses to these four attributes are different from one another so I can move onto looking at other things >_> I've never seen an F-test in R use more than two columns at once though either so I figured why not just go with t? – CapnShanty Apr 08 '17 at 17:36
  • 1
    In small samples t-tests assume normality as well. Both tests are asymptotically valid (i.e. if you've got enough data you can do without assuming normality of the data). F-tests for the equality of several variables are actually fairly common in some disciplines. They go by "omnibus F-test". – RoyalTS Apr 08 '17 at 18:37

0 Answers0