regression {r2spss}R Documentation

Linear Regression

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, and plots of the results mimic the look of SPSS graphs.

Usage

regression(..., data, labels = NULL)

## S3 method for class 'regression_SPSS'
to_SPSS(
  object,
  statistics = c("estimates", "anova", "summary"),
  change = FALSE,
  version = r2spss_options$get("version"),
  ...
)

## S3 method for class 'regression_SPSS'
print(
  x,
  statistics = c("summary", "anova", "estimates"),
  change = FALSE,
  version = r2spss_options$get("version"),
  ...
)

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

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

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

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

## S3 method for class 'regression_SPSS'
plot(
  x,
  y,
  which = c("histogram", "scatter"),
  version = r2spss_options$get("version"),
  ...
)

Arguments

...

for regression, at least one formula specifying a regression model. Different models can be compared by supplying multiple formulas. For the to_SPSS and print methods, additional arguments to be passed down to format_SPSS. For the plot method, additional arguments to be passed down to histSPSS or plotSPSS, in particular graphical parameters. 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.

object, x

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

statistics

a character string or vector specifying which SPSS tables to produce. Available options are "summary" for model summaries, "anova" for ANOVA results, and "estimates" for estimated coefficients. For the to_SPSS method, only one option is allowed (the default is the table of ANOVA results), but the print method allows several options (the default is to print all tables).

change

a logical indicating whether tests on the R^2 change should be included in the table with model summaries (if statistics = "summary"). The default is FALSE.

version

a character string specifying whether the table or plot should mimic the content and look of recent SPSS versions ("modern") or older versions (<24; "legacy"). For the table, the main difference in terms of content is that small p-values are displayed differently.

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.

Details

The print method first calls the to_SPSS method followed by to_latex. Further customization can be done by calling those two functions separately, and modifying the object returned by to_SPSS.

Value

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

models

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

summaries

a list in which each component is an ojbect of class "summary.lm" as returned by the summary method for objects of class "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").

The to_SPSS method returns an object of class "SPSS_table" which contains all relevant information in the required format to produce the LaTeX table. See to_latex for possible components and how to further customize the LaTeX table based on the returned object.

The print method produces a LaTeX table that mimics the look of SPSS output.

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 returns the specified plot for the last model as an object of class "ggplot", which produces the plot when printed.

Note

LaTeX tables that mimic recent versions of SPSS (version = "modern") may require several LaTeX compilations to be displayed correctly.

Author(s)

Andreas Alfons

Examples

# 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)
print(fit3, change  = TRUE)      # print LaTeX table
plot(fit3, which = "histogram")  # diagnostic plot


[Package r2spss version 0.3.2 Index]