knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
library(Lab4RT)
The heart of the package is the function "linreg" which computes the linear regression model and creates the class "linreg" which is used through out the package. The functionality of the package will be illustrated with the "iris" data set.
The linreg() function takes two parameters, a formula for the linear regression model and a data set. It returns a list of the class "linreg". The output below shows what is contained in the class "linreg".
obj <- linreg(formula = Petal.Length ~ Sepal.Width + Sepal.Length, data = iris) obj inherits(obj, "linreg")
"print.linreg" connects the generic function print() to the class and gives it a specific structured output which mimics the output given from the print.lm class.
The function makes it possible to print the same output with print("linreg") and just "linreg"
print(obj)
obj
Using the generic plot() for a object of the "linreg" class prints two plots together. It shows Residuals vs Fitted and standardized residualds vs Fitted values used for verifying model assumptions in linear regression.
plot(obj)
Using the generic function resid() returns the residuals from the class linreg in vector form.
resid(obj)[1:10]
Using the generic function pred() returns the predicted values from the class linreg in vector form.
pred(obj)[1:10]
Using the generic function coef() of a object of class linreg returns the coefficients of the linear regression model.
coef(obj)
Using the generic function gives a summary() on a object of class linreg shows the results of the linear regression model. It mimics the output from using summary() on a object of the lm class.
summary(obj)
The package also includes a custom ggplot2 theme based on the graphical identity of Linköping University (LiU). The theme takes one additional boolean parameter, liu_colors, that will affect what colors are shown in the graph, both for geoms and color/fill aesthetics. Default value for liu_colors is TRUE.
library(ggplot2) ggplot(iris, aes(Petal.Length, Sepal.Width)) + geom_point() + theme_liu(TRUE) ggplot(iris, aes(Species)) + geom_bar() + theme_liu(TRUE) ggplot(iris, aes(Species)) + geom_bar() + theme_liu(FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.