knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
library(regNselect)
First we will examine the lin_model function of the regNselect package. This will be compared to the 'lm' function in R and the 'ols_regress' function of the olsrr package.
install.packages('olsrr') library(olsrr)
We will start by generating random data:
x = rnorm(100) x2 = rnorm(100) x3 = rnorm(100) y = rnorm(100) df = data.frame(y, x, x2, x3)
We will now run each model technique with and compare the output of the three models. We expect all return values to be true.
options(digits = 6) mod_regNselect = lin_model(y~x*x2+x3, data = df) mod_lm = lm(y~x*x2+x3, data = df) mod_olsrr = ols_regress(y~x*x2+x3, data = df) # We will first compare the beta estimates all.equal(mod_regNselect$coefficients, unname(mod_lm$coefficients)) all.equal(mod_regNselect$coefficients, unname(mod_olsrr$betas)) # We will also compare the standard errors of the betas and the test statistics output by olsrr all.equal(mod_regNselect$St.Error, unname(mod_olsrr$std_errors)) all.equal(mod_regNselect$test_statistic, unname(mod_olsrr$tvalues))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.