knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.width = 5, fig.height = 5, out.width = "100%" )
jeksterslabRlinreg
is a collection of functions that I find useful in studying linear regression concepts and methods.
You can install the released version of jeksterslabRlinreg
from GitHub with:
library(devtools) install_github("jeksterslabds/jeksterslabRlinreg")
In this hypothetical example, we are interested in the association between wages and education. The regressor variable is years of education. The regressand variable is hourly wage in US dollars.
wages <- jeksterslabRdatarepo::wages x <- wages$education y <- wages$wages n <- length(x) obj <- lm(y ~ x) beta <- unname(coef(obj)) # covariance structure beta1 <- beta[1] beta2 <- beta[2] sigma2x <- var(x) sigma2y <- var(y) # sigma^2 has some discrepancy # sigma2epsilon <- summary(obj)$sigma^2 sigma2epsilon <- sigma2y - (beta2^2 * sigma2x) # mean structure mux <- mean(x)
x <- as.integer(rnorm(n = n, mean = mux, sd = sqrt(sigma2x))) epsilon <- rnorm(n = n, mean = 0, sd = sqrt(sigma2epsilon)) y <- beta1 + beta2 * x + epsilon X <- cbind( constant = 1, education = x ) y <- matrix( data = y, ncol = 1 ) colnames(y) <- "wages" 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 and years of education
and y
consists of hourly wages
in US dollars.
The output includes the following:
jeksterslabRlinreg::linreg( X = X, y = y )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.