library(ggplot2)
library(methods)
library(lib4af)
data(iris)

Introduction

The lib4af package provides an alternate method of handling linear regression models by using linear algebra, returning the result as an RC class object linreg. The function has two arguments - the formula in order to identify the dependant variable y and independent variables X and the dataset from which the data is derived from.

Info

The package receives the dependant and independent variables y ~ X, as such:

y <- as.matrix(data[all.vars(formula)[1]])
X <- model.matrix(formula, data)

The regression coefficients are calculated using QR decomposition:

QR <- qr(X)
Q <- qr.Q(QR)
R <- qr.R(QR)
Coefficients <<- backsolve(R, crossprod(Q,y))

QR decomposition is the decomposition of a matrix X into a product of an orthogonal matrix Q and an upper triangular matrix R. Additionally, the fitted values, residuals, degrees of freedom, residual variance, regression coefficients variance, t values for each coefficient and p values are calculated using ordinary linear algebra.

Methods

There are several methods implemented in the object linreg:

print()

This method prints out the coefficients and their names.

mod_object <- linreg$new(Petal.Length~Species, data = iris)
mod_object$print()

plot()

This method uses ggplot2 for visualizing, for example "Scale-Location"

mod_object$plot()

resid()

This method returns the residuals.

head(mod_object$resid())

pred()

This method returns the predicted values.

head(mod_object$pred())

coef()

This method returns a named coefficient vector.

mod_object$coef()

summary()

This method returns a similar printout as the summary of lm objects.

mod_object$summary()


afuergut/lib4af documentation built on May 5, 2019, 1:36 p.m.