wgmean: Calculate within group means.

Description Usage Arguments Value Author(s) Examples

View source: R/wgmean.R

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

1
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# 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
             

climwin documentation built on July 1, 2020, 7:04 p.m.