wgmean {climwin} | R Documentation |
Calculate within group means.
Description
Calculate group means of a variable. Used to test for 'between individual effects'. See methods outlined in van de Pol and Wright 2009 for more detail.
Usage
wgmean(covar, groupvar)
Arguments
covar |
Continuous variable for which group means will be calculated. Please specify the dataset in which the variable is found (i.e. data$var). |
groupvar |
Grouping variable within which means will be calculated. For example, individual ID or site/plot ID. Please specify the dataset in which the variable is found (i.e. data$var). |
Value
Returns a vector containing numeric values. This can be used to
differentiate within and between group effects in a model.
See function wgdev
to calculate within group deviance.
See van de Pol and Wright 2009 for more details on the method.
Author(s)
Martijn van de Pol and Jonathan Wright
Examples
# Calculate mean temperature within years from the MassClimate dataset.
data(MassClimate)
#Calculate year column
library(lubridate)
MassClimate$Year <- year(as.Date(MassClimate$Date, format = "%d/%m/%Y"))
#Calculate mean temperature within each year
within_yr_mean <- wgmean(MassClimate$Temp, MassClimate$Year)
#Add this variable to the original dataset
MassClimate$Within_yr_mean <- within_yr_mean
[Package climwin version 1.2.3 Index]