knitr::opts_chunk$set( error = TRUE, collapse = TRUE, comment = "#>", out.width = "100%" )
# The Linear Regression Model {#linreg-estimation-linreg-example}
library(testthat) library(jeksterslabRlinreg)
In this example, we are interested in predictors of wages. The regressor variables are gender, race, union membership, education, and work experience. The regressand variable is hourly wage in US dollars.
See jeksterslabRdatarepo::wages.matrix()
for the data set used in this example.
X <- jeksterslabRdatarepo::wages.matrix[["X"]] # age is removed X <- X[, -ncol(X)] y <- jeksterslabRdatarepo::wages.matrix[["y"]] head(X) head(y)
jeksterslabRlinreg::linreg()
The jeksterslabRlinreg::linreg()
function
fits a linear regression model using X
and y
.
In this example, X
consists of a column of constants,
gender
, race
, union
membership, education
, and work experience
.
and y
consists of hourly wages
in US dollars.
The output includes the following:
linreg( X = X, y = y )
linreg( X = X, y = y, sehatbetahattype = "biased" )
lm()
functionThe lm()
function is the default option for fitting a linear model in R
.
lmobj <- lm( wages ~ gender + race + union + education + experience, data = jeksterslabRdatarepo::wages ) summary(lmobj) # ## `lavaan::sem()` function # # Linear regression in SEM # # # model <- c( # wages ~ gender + race + union + education + experience # ) # # Build errors with lavaan dependency # ### Wishart Likelihood (Unbiased) # # # lavobj <- lavaan::sem( # model = model, # data = jeksterslabRdatarepo::wages, # likelihood = "wishart" # ) # summary(lavobj) # ### Normal Likelihood (Biased) # # # lavobj <- lavaan::sem( # model = model, # data = jeksterslabRdatarepo::wages, # likelihood = "normal" # ) # summary(lavobj)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.