# 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), ]
output <- slidingwin(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 both a linear and quadratic variable climate window using datasets "Offspring"
# and "OffspringClimate".
# Load data.
data(Offspring)
data(OffspringClimate)
# Test both linear and quadratic functions with climate variable temperature
OffspringWin <- slidingwin(xvar = list(Temp = OffspringClimate$Temperature),
cdate = OffspringClimate$Date,
bdate = Offspring$Date,
baseline = glm(Offspring ~ 1, data = Offspring, family = poisson),
range = c(150, 0),
type = "relative", stat = "mean",
func = c("lin", "quad"), cmissing = FALSE, cinterval = "day")
# Examine tested combinations
OffspringWin$combos
# View output for func = "lin"
head(OffspringWin[[1]]$Dataset)
summary(OffspringWin[[1]]$BestModel)
# View output for func = "quad"
head(OffspringWin[[2]]$Dataset)
summary(OffspringWin[[2]]$BestModel)
##EXAMPLE 2##
# Test for an absolute climate window with both 'mean' and 'max' aggregate statistics
# using datasets 'Mass' and 'MassClimate'.
# Load data.
data(Mass)
data(MassClimate)
# Test an absolute window, starting 20 May (refday = c(20, 5))
# Test for climate windows between 100 and 0 days ago (range = c(100, 0))
# Test both mean and max aggregate statistics (stat = c("mean", "max"))
# Fit a linear term (func = "lin")
# Test at the resolution of days (cinterval = "day")
MassWin <- slidingwin(xvar = list(Temp = MassClimate$Temp), cdate = MassClimate$Date,
bdate = Mass$Date, baseline = lm(Mass ~ 1, data = Mass),
range = c(100, 0),
stat = c("mean", "max"), func = "lin",
type = "absolute", refday = c(20, 5),
cmissing = FALSE, cinterval = "day")
# Examine tested combinations
MassWin$combos
# View output for mean temperature
head(MassWin[[1]]$Dataset)
summary(MassWin[[1]]$BestModel)
# View output for max temperature
head(MassWin[[2]]$Dataset)
summary(MassWin[[2]]$BestModel)
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab