Description Usage Arguments Value Note Author(s) See Also Examples
Whereas contr.sum
generates contrasts for factors in
regression models that lead to a (unweighted) sum of estimated
coefficients of zero, this function does so for a weighted sum.
Typically, the weights are the frequencies of the levels of the factor
in the dataset serving to fit the model.
contr.wpoly
adjusts the generated variables for a polynomial
to render them orthogonal for the given frequencies of an ordered
factor instead of doing this only for equal weights.
contr.wsumpoly
will do either of these, depending on the
arguments.
1 2 3 4 5 6 
n 
a factor, a vector of levels for a factor, the number of levels, or a data.frame. 
scores 
scores for the levels of the factor, see

y 
response variable, used to drop observations with NA response 
w 
weights for the levels. If 
contrasts 
a logical indicating whether contrasts should be
computed, see 
sparse 
logical indicating if the result should be sparse (of class 'dgCMatrix'), using package 'Matrix'. 
poly 
(only for 
If n
is a number, a vector of levels, or a factor,
the value is the contrast matrix that can be assigned to
attr(factor, "contrasts")
and then will be used in setting up
the model.matrix for a regression or anova model.
If it is a data.frame, this attribute is attached to each unordered
factor and the complemented data.frame is returned.
Using these contrasts makes individual coefficients interpretable as the effect of the respective level compared to the weighted average of effects. It also makes the intercept – for which the interpretation depends on the choice of contrasts – as precisely estimable as possible.
The function regr
chooses these contrasts as a default
(through the default of userOptions
).
This, however, only works for terms that are factors when before the
formula of the model is translated into the model.frame.
(This will probably change soon.)
Werner A. Stahel, Seminar f. Statistik, ETHZ
link{contrasts}
, link{contr.sum}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19  contr.wsum(factor(c(1,1,1,2,3,3)))
## [,1] [,2]
## 1 1.0 0.0
## 2 0.0 1.0
## 3 1.5 0.5
contr.wpoly(factor(c(1,1,1,2,3,3)))
## ^0 ^1 ^2
## [1,] 1 0.833 0.138
## [2,] 1 0.167 0.828
## [3,] 1 1.167 0.207
data(d.blast)
contr.wsum(d.blast$location)
wg < table(d.blast$location)
( r.blast <
regr(log10(tremor)~location+log10(distance)+log10(charge), data=d.blast) )
sum(wg * r.blast$allcoef$location[,1]) ## approximately 0

Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.