[R] Coding design with repeated measurements in the survey package

ONKELINX, Thierry Thierry.ONKELINX at inbo.be
Thu Apr 28 17:23:00 CEST 2011


Dear all,

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.

Thierry

#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
library(ggplot2)
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
library(survey)
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
library(lme4)
lmer(Y ~ Year + (1|Site), data = Design)

----------------------------------------------------------------------------
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek
team Biometrie & Kwaliteitszorg
Gaverstraat 4
9500 Geraardsbergen
Belgium

Research Institute for Nature and Forest
team Biometrics & Quality Assurance
Gaverstraat 4
9500 Geraardsbergen
Belgium

tel. + 32 54/436 185
Thierry.Onkelinx op inbo.be
www.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 mailing list