[R] svychisq using two frames

lasciel cortevil at msu.edu
Thu May 24 18:10:29 CEST 2012


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.



More information about the R-help mailing list