[R] svychisq using two frames

Thomas Lumley tlumley at uw.edu
Thu May 24 22:44:54 CEST 2012


On Fri, May 25, 2012 at 4:10 AM, lasciel <cortevil at 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



More information about the R-help mailing list