LM.output: Extract Model Residuals and other Regression Diagnostics

View source: R/UBStats_Main_Visible_ALL_202406.R

LM.outputR Documentation

Extract Model Residuals and other Regression Diagnostics

Description

LM.output() Provides fitted values, residuals and other basic quantities used to check the quality of regression fits.

Usage

LM.output(object, data)

Arguments

object

An object returned by function lm.

data

An optional data frame containing the data frame possibly specified in the call of function lm.

Value

A dataframe containing the variables in the model and the model's fitted values, residuals and influence statistics, merged with the dataframe specified in the call of function lm, or with the dataframe possibly specified in data (if it is consistent with the model's output)

Author(s)

Raffaella Piccarreta raffaella.piccarreta@unibocconi.it

Examples

data(MktDATA, package = "UBStats")

# Model and output based on a given dataframe
mod1 <- lm(TotVal ~ Baseline + Kids + Age, data = MktDATA)
# Equivalent calls (since data is specified in lm() 
mod1_out <- LM.output(mod1, data = MktDATA)
dim(mod1_out)
mod1_out <- LM.output(mod1)
dim(mod1_out) # same as above

# Model based on a dataframe's columns
mod2 <- lm(MktDATA$TotVal ~ MktDATA$Baseline + 
           MktDATA$Kids + MktDATA$Age)
mod2_out <- LM.output(mod2)
# note: colnames in mod2_out
colnames(mod2_out)
# note that the dataframe in 'data' is not considered
# as compatible, because the names of columns differ
mod2_out <- LM.output(mod2, data = MktDATA)


UBStats documentation built on Sept. 11, 2024, 6:52 p.m.