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

Description

Imports

library(lab4G3)
library(ggplot2)

Linreg

This package is built after the tasks in advanced programming in R lab 4. The package includes a linear regression estimated using the least squares. The package also contains a series of shortcuts described below.

$\hat{\beta}=(X^TX)^{-1}X^Ty$

$\hat{y}=X\hat{\beta}$

$\hat{e}=y-\hat{y}=y-X\hat{\beta}$.

$df=n-p$

Degrees of freedom where $n$ is number of observations and $p$ is number of predictors

Variance of the model,

$\hat{\sigma^2}=\frac{e^Te}{df}$.

Variance of $\beta$,

$Var(\hat{\beta})=\hat{\sigma^2}(X^TX)^{-1}$.

t-value,

$t_{\beta}=\frac{\hat{\beta}}{\sqrt{Var(\hat{\beta})}}$.

$R^2=1-\frac{\sum(e^2_i)}{\sum(y_i-\bar{y})^2}$

$R^2_{adj}=1-(1-R^2)\times\frac{(n-1)}{(n-p-1)}$

$F=\frac{R^2/(p-1)}{(1-R^2)/(n-p)}$

my_example<-linreg(formula = Petal.Length~.,data=iris)

Coef

Prints the model's coefficients together with its estimated value.

coef(my_example)

Plot

Plots two figures in one figure, the upper image is Residuals vs Fitted, and the lower one is Scale-Location plot.

plot(my_example)

Pred

Returns the predicted values from the linear regression model linreg as a vector.

head(pred(my_example))

Print

Prints the formula and coefficients together with its estimated value.

print(my_example)

Resid

Returns the residuals from the linear regression as a vector.

head(resid(my_example))

Summary

Prints a summary of the information from the linear regression linreg. The formula, coefficients together with its estimated value, standard diviation, t value, p value. And $R^2, R^2_{adj}$ and the F-test.

summary(my_example)


harjew/lab4G3 documentation built on Nov. 4, 2019, 1:27 p.m.