Skip to contents

This function fit a linear model by using stats::lm.

Arguments

dat

Data frame. A data frame containing all variables needed by the formula. Default is dat = self$..cache..$dat.

formula

Formula. Formula for fitting the model. Default is formula = self$null_formula.

cache

Boolean. Whether or not to cache the model. Default is FALSE.

...

Arguments passed to stats::lm.

Value

A fitted linear model.

Examples


# Instantiate
x <- rand_uniform()
e <- rand_normal()
test <- vi_model(prm = list(x = x, e = e),
                 prm_type = list(x = "r", e = "r"),
                 formula = y ~ 1 + x + x^2 + e,
                 null_formula = y ~ x,
                 alt_formula = y ~ x + I(x^2))

test$fit(test$gen(100000))
#> 
#> Call:
#> stats::lm(formula = y ~ x, data = test$gen(1e+05))
#> 
#> Coefficients:
#> (Intercept)            x  
#>      0.8303       2.0135  
#> 

test$fit(test$gen(100000), formula = y ~ x + I(x^2))
#> 
#> Call:
#> stats::lm(formula = y ~ x + I(x^2), data = test$gen(1e+05))
#> 
#> Coefficients:
#> (Intercept)            x       I(x^2)  
#>       1.009        0.952        1.038  
#>