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

From: ONKELINX, Thierry <Thierry.ONKELINX_at_inbo.be>
Date: Thu, 28 Apr 2011 15:23:00 +0000

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.

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_at_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

R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Thu 28 Apr 2011 - 15:27:16 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 28 Apr 2011 - 20:30:36 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.