require("Lab4");
require("ggplot2");
linreg<-linreg$new(formula=Petal.Length ~ Species,data=iris)
linreg$print()

The Lab4 package consists of one function, linreg. Linreg is a function, of class RC, to calculate a linear regression model. The function needs two arguments to work, formula and data. The formula has to be written as a formula, it starts with the response variable followed by "~" and ends with all the explanatory variables. The explanatory variables are seperated by "+".

Ex, Y ~ X1 + X2 + X3

The linreg function contains six subfunctions which print different results. The following functions are implemented:

| Function | Description | |-----------|---------------------------------------------------------------------------| | print() | prints a formula and the coefficients | | plot() | plots 'Residuals vs Fitted' and 'Scale-Location' ggplot2 | | resid() | returns a vector of residuals $\hat{e}$ | | pred() | returns a vector of predicted values $\hat{y}$ | | coef() | returns the coefficients | | summary() | returns the coefficients, standard error, t-values and p-values |

Call the functions

In the following the different functions are described and the corresponding outputs are shown.

The object name is linreg and the functions will therefore be called by linreg$functionname.

print()

The print() prints the formula and the coefficients of the estimated linear regression model.

linreg$print()

plot()

The plot() function uses ggplot2 to plot residuals vs. fitted values and the scale location.

linreg$plot()

resid()

The resid() function returns a vector of the residuals of the estmated linear regression model.

res<-linreg$resid()
head(res,5)

pred()

The pred() function returns a vector of the predicted values of the estimated linear regression model.

pre<-linreg$pred()
head(pre,5)

coef()

The coef() function returns the coefficients of the estimated linear regression model.

coef<-linreg$coef()
head(coef,5)

summary()

The summary() function returns the coefficients, standard errors, t-values and p-values of the estimated linear regression model.

linreg$summary()


GeorgiaEm/732A94_Lab4 documentation built on May 3, 2019, 2:54 p.m.