knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
  )
  library(ggplot2)
  library(gridExtra)
  library(grid)
  library(lab4group8)

Using the linreg package

Introduction

This package provides a Linear Regression Model as a function that returns the model as an Object.

Running the model

To run the model you need to input a formula and a dataset. This example uses the dataset iris, which is standard include in R.

  data(iris)

The model is of the form y~x, where y is the Sepal length depending on the x, the petal length.

  linreg1 <- linreg(Sepal.Length~Petal.Length, data = iris)

In the command above we create an object of the class linreg which contains all the information that we need.

Methods

The linreg object can be manipulated by using six different methods:

print()

linreg1$print() prints the coefficients.

  linreg1$print()

plot()

linreg1$plot() plots two graphs. The first plots the Residuals vs the Fitted values. The second is a Scale-Locationo plot.

  linreg1$plot()

resid()

linreg1$resid() returns a vector with the residuals.

  head(linreg1$resid())

pred()

linreg1$pred() returns a vector with the predicted values.

  head(linreg1$pred())

coef()

linreg1$coef() returns the intercept plus the coefficients.

  linreg1$coef()

summary()

linreg1$summary() prints the coefficients with their standard error, t-values, and p-value, plus the estimate of standard deviation of the variance and the degrees of freedom.

  linreg1$summary()


Jorisvdoorn/lab4group8 documentation built on Oct. 30, 2019, 8:01 p.m.