regression: Linear Regression

Description Usage Arguments Value Author(s) Examples

View source: R/regression.R

Description

Perform linear regression on variables of a data set. The output is printed as a LaTeX table that mimics the look of SPSS output (version <24), and plots of the results mimic the look of SPSS graphs.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
regression(..., data, labels = NULL, change = FALSE)

## S3 method for class 'regressionSPSS'
print(x, digits = 3, statistics = c("summary", "anova", "estimates"), ...)

## S3 method for class 'regressionSPSS'
coef(object, ...)

## S3 method for class 'regressionSPSS'
df.residual(object, ...)

## S3 method for class 'regressionSPSS'
fitted(object, standardized = FALSE, ...)

## S3 method for class 'regressionSPSS'
residuals(object, standardized = FALSE, ...)

## S3 method for class 'regressionSPSS'
plot(
  x,
  y,
  which = c("histogram", "scatter"),
  main = NULL,
  xlab = NULL,
  ylab = NULL,
  ...
)

Arguments

...

for regression, at least one formula specifying a regression model. Different models can be compared by supplying multiple formulas. For the plot method, additional arguments to be passed down, in particular graphical parameters (see also histSPSS and plotSPSS). For other methods, this is currently ignored.

data

a data frame containing the variables.

labels

a character or numeric vector giving labels for the regression models in the output tables.

change

a logical indicating whether tests on the R-squared change should be included in model summaries.

x, object

an object of class "regressionSPSS" as returned by function regression.

digits

an integer giving the number of digits after the comma to be printed in the LaTeX tables.

statistics

a character vector specifying which LaTeX tables should be printed. Available options are "summary" for model summaries, "anova" for ANOVA results, and "estimates" for estimated coefficients. The default is to print all tables.

standardized

a logical indicating whether to return standardized residuals and fitted values (TRUE), or residuals and fitted values on their original scale (FALSE).

y

ignored (only included because it is defined for the generic function plot).

which

a character string specifying which plot to produce. Possible values are "histogram" for a histogram of the residuals, or "scatter" for a scatterplot of the standardized residuals against the standardized fitted values.

main, xlab, ylab

the plot title and axis labels.

Value

An object of class "regressionSPSS" with the following components:

models

a list in which each component is an ojbect of class "lm" as returned by function lm.

response

a character string containing the name of the response variable.

method

a character string specifying whether the nested models are increasing in dimension by entering additional variables ("enter") or decreasing in dimension by removing variables ("remove").

change

a logical indicating whether tests on the R-squared change are included in model summaries.

The print method produces a LaTeX table that mimics the look of SPSS output (version <24).

The coef, df.residual, fitted and residuals methods return the coefficients, residual degrees of freedom, fitted values and residuals, respectively, of the last model (to mimic SPSS functionality).

Similarly, the plot method creates the specified plot for the last model.

Author(s)

Andreas Alfons

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# load data
data("Eredivisie")
# log-transform market values
Eredivisie$logMarketValue <- log(Eredivisie$MarketValue)
# squared values of age
Eredivisie$AgeSq <- Eredivisie$Age^2

# simple regression model of log market value on age
fit1 <- regression(logMarketValue ~ Age, data = Eredivisie)
fit1                           # print LaTeX table
plot(fit1, which = "scatter")  # diagnostic plot

# add a squared effect for age
fit2 <- regression(logMarketValue ~ Age + AgeSq,
                   data = Eredivisie, labels = 2)
fit2                           # print LaTeX table
plot(fit2, which = "scatter")  # diagnostic plot

# more complex models with model comparison
fit3 <- regression(logMarketValue ~ Age + AgeSq,
                   logMarketValue ~ Age + AgeSq + Contract +
                                    Foreign,
                   logMarketValue ~ Age + AgeSq + Contract +
                                    Foreign + Position,
                   data = Eredivisie, labels = 2:4,
                   change = TRUE)
fit3                             # print LaTeX table
plot(fit3, which = "histogram")  # diagnostic plot

r2spss documentation built on Nov. 25, 2021, 1:06 a.m.