Exercise

# Weighted effects coding

Weighted effects coding differs from unweighted effects coding with respect to the weights, fractions. A reference category is chosen and the weights form the following dummy coding scheme:

$$ \begin{aligned} \begin{matrix} \mathrm{dummy} & 1 & 2 & ... & N-1 \\ \hline & \frac{-n_2}{n_1} & \frac{-n_3}{n_1} & ... & \frac{-n_N}{n_1} \\ & \frac{n_2}{n_1} & 0 & ... & 0 \\ & 0 & \frac{n_3}{n_1} & ... & 0 \\ & 0 & 0 & ... & \frac{n_N}{n_1} \end{matrix} \end{aligned} $$

with n = the number of observations of each group and index N = the number of levels. The weights represent the number of observation of a non-reference category relative to those of the reference category.

If the weights are computed, the regression of the dependent variable against the non-categorical and categorical variables using the weighted effects coding scheme can start.

Instructions

**100 XP**

- Transform the nominal variable
`dept`

into a factor variable`dept.g`

. Use the`factor()`

function. - Apply the
`contrasts()`

function on the factor variable`dept.g`

. This function allows to set the contrasts which are associated with`dept.g`

. - The weights for each dummy are already computed and combined in the
`weights`

matrix (available in your workspace). Assign this`weights`

matrix to`contrasts(dept.g)`

. In this way, you set the contrasts associated with factor dept.g equal to the weights matrix. - Regress
`salary`

against`dept.g`

by using the`lm()`

function. Name the model`model_weighted`

. - Apply the
`summary()`

function to obtain a summary of the regression results.