# NOT RUN {
#Simple test example
#Create data from a subset of our test dataset
#Just use two years
biol_data <- Mass[1:2, ]
clim_data <- MassClimate[grep(pattern = "1979|1986", x = MassClimate$Date), ]
rand <- randwin(repeats = 1, xvar = list(Temp = clim_data$Temp),
cdate = clim_data$Date,
bdate = biol_data$Date,
baseline = lm(Mass ~ 1, data = biol_data),
range = c(1, 0),
type = "relative", stat = "mean",
func = c("lin"), cmissing = FALSE, cinterval = "day")
# }
# NOT RUN {
# Full working examples
## EXAMPLE 1 ##
# Test climate windows in randomised data using a sliding window approach.
data(Mass)
data(MassClimate)
# Randomise data twice
# Note all other parameters are fitted in the same way as the climatewin function.
rand <- randwin(repeats = 2, window = "sliding",
xvar = list(Temp = MassClimate$Temp),
cdate = MassClimate$Date, bdate = Mass$Date,
baseline = lm(Mass ~ 1, data = Mass),
range = c(100, 0),
stat = "mean", func = "lin", type = "absolute",
refday = c(20, 5),
cmissing = FALSE, cinterval = "day")
# View output #
head(rand)
## EXAMPLE 2 ##
# Test climate windows in randomised data using a weighted window approach.
data(Offspring)
data(OffspringClimate)
# Randomise data twice
# Note all other parameters are fitted in the same way as the weightwin function.
weightrand <- randwin(repeats = 2, window = "weighted",
xvar = list(Temp = OffspringClimate$Temperature),
cdate = OffspringClimate$Date,
bdate = Offspring$Date,
baseline = glm(Offspring ~ 1, family = poisson, data = Offspring),
range = c(365, 0), func = "quad",
type = "relative", 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(weightrand)
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab