Learn R Programming

climwin (version 0.1.2)

weightwin: Find a weighted climate window

Description

Finds the best weighted average of a weather variable over a period that correlates most strongly with a biological variable. Uses weibull or Generalised Extreme Value (GEV) distribution. See references for a full description.

Usage

weightwin(xvar, cdate, bdate, baseline, furthest, closest, func = "lin",
  type = "fixed", cutoff.day, cutoff.month, weightfunc = "W",
  cinterval = "day", par = c(3, 0.2, 0), control = list(ndeps = c(0.01,
  0.01, 0.01)), method = "L-BFGS-B")

Arguments

xvar
A list object containing all climate variables of interest. Please specify the parent environment and variable name (e.g. Climate$Temp).
cdate
The climate date variable. Please specify the parent environment and variable name (e.g. Climate$Date).
bdate
The biological date variable. Please specify the parent environment and variable name (e.g. Biol$Date).
baseline
The baseline model structure used for testing correlation. Currently known to support lm, lme, glm and glmer objects.
furthest
The furthest number of time intervals (set by cinterval) back from the cutoff date or biological record that will be included in the climate window search.
closest
The closest number of time intervals (set by cinterval) back from the cutoff date or biological record that will be included in the climate window search.
func
The function used to fit the climate variable in the model. Can be linear ("lin"), quadratic ("quad"), cubic ("cub"), inverse ("inv") or log ("log").
type
fixed or variable, whether you wish the climate window to be variable (i.e. the number of days before each biological record is measured) or fixed (i.e. number of days before a set point in time).
cutoff.day,cutoff.month
If type is "fixed", the day and month of the year from which the fixed window analysis will start.
weightfunc
The distribution to be used for optimisation. Can be either a Weibull ("W") or Generalised Extreme Value distribution ("G").
cinterval
The resolution at which the climate window analysis will be conducted. May be days ("day"), weeks ("week"), or months ("month"). Note the units of parameters 'furthest' and 'closest' will differ depending on the choice of cinterval.
par
Shape, scale and location parameters of the Weibull of GEV weight function used as start weight function. For Weibull : Shape and scale parameters must be greater than 0, while location parameter must be less than or equal to 0. For GEV : Scale paramet
control
Parameters used to determine step size for the optimisation function. Please see optim for more detail.
method
The method used for the optimisation function. Please see optim for more detail.

Value

  • Produces a constantly updating grid of plots as the optimisation function is running.
    • Right panel from top to bottom: The three parameters (shape, scale and location) determining the weight function.
    • Left top panel: The resulting weight function.
    • Right middle panel: The delta AICc compared to the baseline model.
    • Right bottom panel: The weighted mean of climate for the current weight function.
    Also returns a list containing three objects:
    • BestModel, a model object. The best weighted window model determined by AICc.
    • BestModelData, a dataframe. Biological and climate data used to fit the best weighted window model.
    • WeightedOutput, a list. Parameter values for the best weighted window.

References

van de Pol & Cockburn 2011 Am Nat 177(5):698-707 (doi: 10.1086/659101) "Identifying the critical climatic time window that affects trait expression"

Examples

Run this code
# 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