contr.wec.weighted: Calculates contrasts for a weighted factor variable based on...

Description Usage Arguments Value Author(s) Examples

Description

Function works equivalent to contr.wec from the wec package, but allows for weighted contrasts.

Usage

1
contr.wec.weighted (x, omitted, weights)

Arguments

x

grouping variable of class factor

omitted

Label of the factor label that should be taken as the omitted category

weights

Numeric vector of non-negative weights

Value

Returns a contrast matrix based on weighted effect coding.

Author(s)

Sebastian Weirich, based upon the contr.wec function of the wec package

Examples

1
2
3
4
5
6
7
8
### exemplary data according to wec paper
dat <- data.frame ( group = as.factor(c(rep(1,3), rep(2,2))), wgt = c(2/3, 4/3, 2, 3/8, 5/8))
### default contrasts
contrasts(dat[,"group"])
### weighted effect coding for weighted data
contr.wec.weighted(x= dat[,"group"], omitted=1,weights=dat[,"wgt"])
### equal to weighted effect coding: wec::contr.wec(x= dat[,"group"], omitted=1)
contr.wec.weighted(x= dat[,"group"], omitted=1,weights=rep(1, nrow(dat)))

eatTools documentation built on Nov. 10, 2021, 5:07 p.m.