[R] svychisq??

Thomas Lumley tlumley at uw.edu
Thu May 31 23:34:43 CEST 2012


On Fri, Jun 1, 2012 at 6:07 AM, Diana Marcela Martinez Ruiz
<dianammr06 at 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



More information about the R-help mailing list