knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library(Lab4HugoOtto)

The linreg function

The Lab4HugoOtto package provides the linreg function which is used to fit linear models. The linreg function can take two arguments (formula, data) and returns a list with class linreg which include Regressions coefficients, the fitted values, the residuals, the degrees of freedom, the residual variance, the variance of the regression coefficients and the t-values for each coefficient.

iris <- datasets::iris
linreg_obj <- linreg(Petal.Length~Species, iris)

Methods for linreg objects

The package also provides several generic methods for objects of the class linreg, which can be used to analyze different aspects of the results from the linear regression. Here follows a short description of each method.

print.linreg

The print.linreg method will return the estimated coefficients from the regression model along with their names.

print(linreg_obj)

plot.linreg

The plot.linreg method will return two plots using the ggplot2 package. The two plots returned are the Residuals vs Fitted plot as well as the Scale-Location plot.

plot(linreg_obj)

residuals.linreg

The residuals.linreg method will return the residuals from the regression model as a vector.

head(resid(linreg_obj))

predict

The predict.linreg method will return the predicted values from the regression model as a vector.

head(predict(linreg_obj))

coef.linreg

The coef.linreg method will return the coefficients from the regression model as a named vector.

coef(linreg_obj)

theme_linkoping

Finally the package provides a theme for plots created with the ggplot2 package. This is a basic theme that controls the size of the plot title, the axis titles and the axis text. It also sets the colors of the plot title and axis title to a blue hue that matches the base color in the graphical manual of Linkoping University.



hugkn566/Lab4HugoOtto documentation built on Oct. 20, 2020, 2:17 p.m.