r11 -- r16 are variables showing a reason for usage of a product in 6 different situations. Each variable is a factor with 4 levels imported from a SPSS sav file with labels ranging from "not important" to "very important", and NA's for a sample of N = 276. (1) I need a chi square test of independence showing that the reason does not differ depending on the situation. (2) I need a single coloured histogram plot. The x axis should be grouped by the 6 situation with small space between the groups, each group should show different bars for each factor value ("not important", "little...", ..., "NA's"), but NA's is not necessary. I've been googling the whole day, searching the mailing list and handbooks, and struggled through the somewhat R programmer specific documentation. Beeing a newby in R, I'm now afraid that I have to go back to SPSS and Excel where my tasks would be a work of an hour. But I was told "euphoric" that R may solve many of the problems I have (and don't like) with SPSS, or having to separate calculation (SPSS, Excel by hand) and plotting (GNUplot). So my two questions are: How can I easily solve my 2 tasks? Secondly, is R really recommended for R newbys in daily work? Thank you for any help S?ren
soeren.vogel at eawag.ch wrote:> r11 -- r16 are variables showing a reason for usage of a product in 6 > different situations. Each variable is a factor with 4 levels imported > from a SPSS sav file with labels ranging from "not important" to "very > important", and NA's for a sample of N = 276. > > (1) I need a chi square test of independence showing that the reason > does not differ depending on the situation. > > (2) I need a single coloured histogram plot. The x axis should be > grouped by the 6 situation with small space between the groups, each > group should show different bars for each factor value ("not > important", "little...", ..., "NA's"), but NA's is not necessary. > > I've been googling the whole day, searching the mailing list and > handbooks, and struggled through the somewhat R programmer specific > documentation. Beeing a newby in R, I'm now afraid that I have to go > back to SPSS and Excel where my tasks would be a work of an hour. But > I was told "euphoric" that R may solve many of the problems I have > (and don't like) with SPSS, or having to separate calculationdd <- subset(yourdata, select=r11:r16) (1) is not a straightforward chi-square.... What _would_ you do in SPSS? You might do it in an hour, but I suspect it wouldn't be right.... In R, possibly, friedman.test(as.matrix(dd)) (2) M <- sapply(dd,table) barplot(M, beside=TRUE) (getting the axis labels exactly right can be a bit tricky, though.)> (SPSS, Excel by hand) and plotting (GNUplot). > > So my two questions are: How can I easily solve my 2 tasks? Secondly, > is R really recommended for R newbys in daily work? > > Thank you for any help > > S?ren > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.-- O__ ---- Peter Dalgaard ?ster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
soeren.vogel at eawag.ch wrote:> r11 -- r16 are variables showing a reason for usage of a product in 6 > different situations. Each variable is a factor with 4 levels imported > from a SPSS sav file with labels ranging from "not important" to "very > important", and NA's for a sample of N = 276. > > (1) I need a chi square test of independence showing that the reason > does not differ depending on the situation. > > (2) I need a single coloured histogram plot. The x axis should be > grouped by the 6 situation with small space between the groups, each > group should show different bars for each factor value ("not > important", "little...", ..., "NA's"), but NA's is not necessary. > > I've been googling the whole day, searching the mailing list and > handbooks, and struggled through the somewhat R programmer specific > documentation. Beeing a newby in R, I'm now afraid that I have to go > back to SPSS and Excel where my tasks would be a work of an hour. But > I was told "euphoric" that R may solve many of the problems I have > (and don't like) with SPSS, or having to separate calculation (SPSS, > Excel by hand) and plotting (GNUplot). > > So my two questions are: How can I easily solve my 2 tasks? Secondly, > is R really recommended for R newbys in daily work?Hi Soeren, For number 1: chisq.test(svfreqs) #see below but I don't think that this is the best way to test this. For number 2: faclevels<-c("Not","Little","Somewhat","Very") svdf<-data.frame(r11=sample(faclevels,276,TRUE), r12=sample(faclevels,276,TRUE), r13=sample(faclevels,276,TRUE), r14=sample(faclevels,276,TRUE), r15=sample(faclevels,276,TRUE), r16=sample(faclevels,276,TRUE)) library(prettyR) svfreqs<-t(matrix(unlist(sapply(svdf,freq,display.na=FALSE)),nrow=6,byrow=TRUE)) library(plotrix) barp(svfreqs,main="Frequencies of importance ratings",ylim=c(0,100), names.arg=paste("r1",1:6,sep=""),col=2:5,xlab="Situation", ylab="Frequency") legend(2.3,98,c("Not","Little","Somewhat","Very"),fill=2:5) Jim