# Test for a weighted average over a fixed climate window
# using datasets 'Offspring' and 'OffspringClimate'
# N.B. THIS EXAMPLE MAY TAKE A MOMENT TO CONVERGE ON THE BEST MODEL.
# Load data
data(Offspring)
data(OffspringClimate)
# Test for climate windows between 365 and 0 days ago (furthest=365, closest=0)
# Fit a quadratic term for the mean weighted climate (func="quad")
# in a Poisson regression (offspring number ranges 0-3)
# Test a variable window (type = "fixed")
# Test at the resolution of days (cinterval="day")
# Uses a Weibull weight function (weightfunc="week")
weight <- weightwin(xvar = list(Temp = OffspringClimate$Temperature),
cdate = OffspringClimate$Date,
bdate = Offspring$Date,
baseline = glm(Offspring ~ 1, family = poisson, data = Offspring),
furthest = 365, closest = 0, func = "quad",
type = "variable", weightfunc = "W", cinterval = "day",
par = c(3, 0.2, 0), control = list(ndeps = c(0.01, 0.01, 0.01)),
method = "L-BFGS-B")
# View output
head(weight[[3]])
summary(weight[[1]])
head(weight[[2]])Run the code above in your browser using DataLab