[R] Coding design with repeated measurements in the survey package
Thierry.ONKELINX at inbo.be
Thu Apr 28 17:23:00 CEST 2011
I'm working on a design with rotating panels. Each site is sampled every X year. Have a look at the code below the get an idea of the design. In reality the number of sites will be (much) higher.
However I'm not sure if I coded the design correctly in svydesign(). Can someone confirm that it is either correct or wrong? I've added the lmer() equivalent that I want to replicate with svyglm(). Since the number of sites in the population is limited, I'll need to use the finite population correction.
Thanks in advance.
#create a small design
nCycle <- 3
nYearPerCycle <- 3
nSitePerYear <- 5
Design <- expand.grid(SiteInYear = seq_len(nSitePerYear), YearInCycle = seq_len(nYearPerCycle), Cycle = seq_len(nCycle))
Design$Year <- (Design$Cycle - 1)*nYearPerCycle + Design$YearInCycle
Design$Site <- Design$SiteInYear + (Design$YearInCycle - 1) * nSitePerYear
#plot the design
#points indicate in which year a site is sampled
#lines connect the sites
ggplot(Design, aes(x = Year, y = Site, group = Site)) + geom_point() + geom_line()
#create some dummy data
Intercept <- 10
Trend <- -0.25
SiteEffect <- rnorm(nSitePerYear * nYearPerCycle, sd = 2)
Design$Y <- Intercept + Trend * Design$Year + SiteEffect[Design$Site] + rnorm(nrow(Design), sd = 1)
ggplot(Design, aes(x = Year, y = Y)) + geom_point() + geom_line(aes(group = Site))
#my attempt of coding the design
Design$fpc <- 0.0001
SVD <- svydesign(id = ~ Site, data = Design, variables = Y ~ Year, pps = "brewer", fpc = ~fpc)
#this is the analysis I would like to perform
svyglm(Y ~ Year, SVD)
#the mixed models approach
lmer(Y ~ Year + (1|Site), data = Design)
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek
team Biometrie & Kwaliteitszorg
Research Institute for Nature and Forest
team Biometrics & Quality Assurance
tel. + 32 54/436 185
Thierry.Onkelinx op inbo.be
To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of.
~ Sir Ronald Aylmer Fisher
The plural of anecdote is not data.
~ Roger Brinner
The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data.
~ John Tukey
More information about the R-help