knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
library(lab4package)
This linear regression package contains a reference class which computes the coefficients, residuals, predicted values, standard errors for both the coefficients and the residuals, t-values and p-values, and the degrees of freedom of a model matrix based on a provided formula and data set.
The reference class is called "linreg". It can be created by supplying a formula and a data set like so:
data("iris") linreg_mod = linreg$new(Petal.Length~Sepal.Width+Sepal.Length, iris)
After the class has been created, several functions can be called.
The coef() function returns a named vector of coefficients.
data("iris") linreg_mod <- linreg$new(Petal.Length~Sepal.Width+Sepal.Length, iris) linreg_mod$coef()
The pred() function returns the predicted values.
data("iris") linreg_mod = linreg$new(Petal.Length~Sepal.Width+Sepal.Length, iris) linreg_mod$pred()
The resid() function returns the predicted values.
data("iris") linreg_mod = linreg$new(Petal.Length~Sepal.Width+Sepal.Length, iris) linreg_mod$resid()
The print() function shows how the function was called and also prints the coefficients.
data("iris") linreg_mod = linreg$new(Petal.Length~Sepal.Width+Sepal.Length, iris) linreg_mod$print()
The summary() function shows a detailed overview of all the relevant variables.
data("iris") linreg_mod = linreg$new(Petal.Length~Sepal.Width+Sepal.Length, iris) linreg_mod$summary()
The plot() function displays two graphs; the first graph shows the relationship between the residuals and the fitted values, and the second graph shows the scale-location.
data("iris") linreg_mod = linreg$new(Petal.Length~Species, iris) linreg_mod$plot()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.