Re: [R] svychisq??
Hello forum, I want to do a test of independence with svychisq, but I get an error, then this my code: am18 - read.spss(C:/Users/diana/Dropbox/Semestre 10/Tesis 10/Tesis Diana/AMcomuna18-29MAR2012.sav, use.value.labels=TRUE, max.value.labels=Inf, to.data.frame=TRUE) b-matrix(c(am18$N6_MANZANA),ncol=1) c-matrix(c(am18$PM1_1_PONDEMUESTRA),ncol=1) d-matrix(c(am18$M1_3_ESTRATO),ncol=1) e-matrix(c(rep(0.078,315)),ncol=1) Muestra.comp-svydesign(id=~b,strata =~d,nest=TRUE,weights=~c,data=am18, fpc=~e) ocupacion -matrix(c(am18$M1_19_OCUPACIONPRINCIPALACTUAL),ncol=1) APES-matrix(c(am18$M3_11_AUTOPERCEPCIONSALUDGENERAL),ncol=1) tbl1-svytable(~ocupacion+APES,Muestra.comp) summary(tbl1, statistic=Chisq) Error en `[.data.frame`(design$variables, , as.character(rows)) : undefined columns selected when I call am18 at the end says it is a data.frame (to.data.frame = TRUE)) and by that I aprace error. I would appreciate help with this problem [[alternative HTML version deleted]] __ R-help@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.
Re: [R] svychisq??
On Fri, Jun 1, 2012 at 6:07 AM, Diana Marcela Martinez Ruiz dianamm...@hotmail.com wrote: Hello forum, I want to do a test of independence with svychisq, but I get an error, then this my code: am18 - read.spss(C:/Users/diana/Dropbox/Semestre 10/Tesis 10/Tesis Diana/AMcomuna18-29MAR2012.sav, use.value.labels=TRUE, max.value.labels=Inf, to.data.frame=TRUE) b-matrix(c(am18$N6_MANZANA),ncol=1) c-matrix(c(am18$PM1_1_PONDEMUESTRA),ncol=1) d-matrix(c(am18$M1_3_ESTRATO),ncol=1) e-matrix(c(rep(0.078,315)),ncol=1) Muestra.comp-svydesign(id=~b,strata =~d,nest=TRUE,weights=~c,data=am18, fpc=~e) ocupacion -matrix(c(am18$M1_19_OCUPACIONPRINCIPALACTUAL),ncol=1) APES-matrix(c(am18$M3_11_AUTOPERCEPCIONSALUDGENERAL),ncol=1) tbl1-svytable(~ocupacion+APES,Muestra.comp) summary(tbl1, statistic=Chisq) Error en `[.data.frame`(design$variables, , as.character(rows)) : undefined columns selected when I call am18 at the end says it is a data.frame (to.data.frame = TRUE)) and by that I aprace error. I would appreciate help with this problem Variables that you refer to with a formula have to be in the design object. You don't need to turn the variables into matrices, so you could just do tbl1-svytable(~M1_19_OCUPACIONPRINCIPALACTUAL+M3_11_AUTOPERCEPCIONSALUDGENERAL,Muestra.comp) or if you want shorter names, create renamed variables in the design object: Muestra.comp - update(Muestra.comp, ocupacion = M1_19_OCUPACIONPRINCIPALACTUAL, APES= M3_11_AUTOPERCEPCIONSALUDGENERAL) -thomas -- Thomas Lumley Professor of Biostatistics University of Auckland __ R-help@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.
[R] svychisq using two frames
Hello, I’m hoping you have a few minutes to help out someone very new to R. I’ve done some searching, but cannot find this particular issue. I have survey data from two different time periods (years). Both years are stratified samples and have the same variables (and variable names), but are different people in the community answering in the different years. Everything loads into the survey design fine and I can calculate the means and CIs I need. I want to calculate whether there was a change in a single variable between years. The variable of interest has binary yes/no answers. I was planning to use the ‘svychisq’ function, but cannot figure out how to do this across what is currently two data frames. I haven’t actually tried to run a svychisq with the two frames yet as I am waiting on the data for the second frame. I’m trying to plan out the logic ahead of time. So, let’s say I have survey design frame Year1 with variables Wt1 and MyVar, and survey design frame Year2 with variables Wt2 and MyVar – remember the variable name is the same in both frames. My first inclination is that I would use a statement like: svychisq(~MyVar+MyVar, Year1+Year2, statistic=”Chisq”) However, it seems from reading the help files that I can only use the ‘svychisq’ function if I declare a single data frame in the design statement, rather than referencing a frame for Year1 and a different frame for Year2. So, I could use ‘rbind’ to stack the two years of data together with their appropriate weights into a single data frame. svychisq(~MyVar+MyVar, BothYears, statistic=”Chisq”) But now I have a problem that the variable name is the same across years, so how do I differentiate the different time periods in the syntax for the formula? Do I need to also create two new variables per: MyVar.1 [year = 1] - MyVar MyVar.2 [year = 2] - MyVar svychisq(~MyVar.1+MyVar.2, BothYears, statistic=”Chisq”, na.rm= TRUE) (I feel like I may be overthinking this and the answer is much simpler) -- View this message in context: http://r.789695.n4.nabble.com/svychisq-using-two-frames-tp4631220.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
Re: [R] svychisq using two frames
On Fri, May 25, 2012 at 4:10 AM, lasciel corte...@msu.edu wrote: So, I could use ‘rbind’ to stack the two years of data together with their appropriate weights into a single data frame. svychisq(~MyVar+MyVar, BothYears, statistic=”Chisq”) But now I have a problem that the variable name is the same across years, so how do I differentiate the different time periods in the syntax for the formula? Do I need to also create two new variables per: MyVar.1 [year = 1] - MyVar MyVar.2 [year = 2] - MyVar svychisq(~MyVar.1+MyVar.2, BothYears, statistic=”Chisq”, na.rm= TRUE) (I feel like I may be overthinking this and the answer is much simpler) You don't need to create two new variables; you just need a year variable svychisq(~MyVar+Year, BothYears, statistic=”Chisq”, na.rm= TRUE) tests whether MyVar is independent of Year. -thomas -- Thomas Lumley Professor of Biostatistics University of Auckland __ R-help@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.