Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

scalewt

Compute or scale data using (weighted) means, variances and covariances (possibly for the levels of a factor)


Description

These utility functions compute (weighted) means, variances and covariances for dataframe partitioned by a factor. The scale transforms a numeric matrix in a centred and scaled matrix for any weighting.

Usage

covwt(x, wt, na.rm = FALSE)
varwt(x, wt, na.rm = FALSE)
scalewt(df, wt = rep(1/nrow(df), nrow(df)), center = TRUE, scale = TRUE)
meanfacwt(df, fac = NULL, wt = rep(1/nrow(df), nrow(df)), drop = FALSE)
varfacwt(df, fac = NULL, wt = rep(1/nrow(df), nrow(df)), drop = FALSE)
covfacwt(df, fac = NULL, wt = rep(1/nrow(df), nrow(df)), drop = FALSE)
scalefacwt(df, fac = NULL, wt = rep(1/nrow(df), nrow(df)), scale = TRUE, drop = FALSE)

Arguments

x

a numeric vector (varwt) or a matrix (covwt) containg the data.

na.rm

a logical value indicating whether NA values should be stripped before the computation proceeds.

df

a matrix or a dataframe containing the data.

fac

a factor partitioning the data.

wt

a numeric vector of weights.

drop

a logical value indicating whether unused levels should be kept.

scale

a logical value indicating whether data should be scaled or not.

center

a logical value indicating whether data should be centered or not.

Details

Functions returns biased estimates of variances and covariances (i.e. divided by n and not n-1)

Value

For varwt, the weighted variance. For covwt, the matrix of weighted co-variances. For scalewt, the scaled dataframe. For other function a list (if fac is not null) of dataframes with approriate values

Author(s)

Examples

data(meau)
w <- rowSums(meau$spe)
varwt(meau$env, w)
varfacwt(meau$env, wt = w)
varfacwt(meau$env, wt = w, fac = meau$design$season)
covfacwt(meau$env, wt = w, fac = meau$design$season)
scalewt(meau$env, wt = w)

ade4

Analysis of Ecological Data: Exploratory and Euclidean Methods in Environmental Sciences

v1.7-16
GPL (>= 2)
Authors
Stéphane Dray <stephane.dray@univ-lyon1.fr>, Anne-Béatrice Dufour <anne-beatrice.dufour@univ-lyon1.fr>, and Jean Thioulouse <jean.thioulouse@univ-lyon1.fr>, with contributions from Thibaut Jombart, Sandrine Pavoine, Jean R. Lobry, Sébastien Ollier, Daniel Borcard, Pierre Legendre, Stéphanie Bougeard and Aurélie Siberchicot. Based on earlier work by Daniel Chessel.
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.