# fix.coef: Fix coefficients and update model In mice: Multivariate Imputation by Chained Equations

## Description

Refits a model with a specified set of coefficients.

## Usage

 `1` ```fix.coef(model, beta = NULL) ```

## Arguments

 `model` An R model, e.g., produced by `lm` or `glm` `beta` A numeric vector with `length(coef)` model coefficients. If the vector is not named, the coefficients should be given in the same order as in `coef(model)`. If the vector is named, the procedure attempts to match on names.

## Details

The function calculates the linear predictor using the new coefficients, and reformulates the model using the `offset` argument. The linear predictor is called `offset`, and its coefficient will be `1` by definition. The new model only fits the intercept, which should be `0` if we set `beta = coef(model)`.

## Value

An updated R model object

## Author(s)

Stef van Buuren, 2018

## Examples

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34``` ```model0 <- lm(Volume ~ Girth + Height, data = trees) formula(model0) coef(model0) deviance(model0) # refit same model model1 <- fix.coef(model0) formula(model1) coef(model1) deviance(model1) # change the beta's model2 <- fix.coef(model0, beta = c(-50, 5, 1)) coef(model2) deviance(model2) # compare predictions plot(predict(model0), predict(model1)) abline(0, 1) plot(predict(model0), predict(model2)) abline(0, 1) # compare proportion explained variance cor(predict(model0), predict(model0) + residuals(model0))^2 cor(predict(model1), predict(model1) + residuals(model1))^2 cor(predict(model2), predict(model2) + residuals(model2))^2 # extract offset from constrained model summary(model2\$offset) # it also works with factors and missing data model0 <- lm(bmi ~ age + hyp + chl, data = nhanes2) model1 <- fix.coef(model0) model2 <- fix.coef(model0, beta = c(15, -8, -8, 2, 0.2)) ```

### Example output  ```Attaching package: ‘mice’

The following object is masked from ‘package:stats’:

filter

The following objects are masked from ‘package:base’:

cbind, rbind

Volume ~ Girth + Height
(Intercept)       Girth      Height
-57.9876589   4.7081605   0.3392512
 421.9214
Volume ~ 1
(Intercept)
3.988039e-14
 421.9214
(Intercept)
-62.07097
 1098.984
 0.94795
 0.94795
 0.9228528
Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
57.00   82.00   87.00   92.24  102.25  140.00
```

mice documentation built on Nov. 24, 2021, 5:06 p.m.