regression | R Documentation |
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.
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"), ... )
... |
for |
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 |
statistics |
a character string or vector specifying which SPSS tables
to produce. Available options are |
change |
a logical indicating whether tests on the
R-squared change should be included in the table with model
summaries (if |
version |
a character string specifying whether the table or plot
should mimic the content and look of recent SPSS versions ( |
standardized |
a logical indicating whether to return standardized
residuals and fitted values ( |
y |
ignored (only included because it is defined for the generic
function |
which |
a character string specifying which plot to produce. Possible
values are |
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
.
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.
LaTeX tables that mimic recent versions of SPSS (version = "modern"
)
may require several LaTeX compilations to be displayed correctly.
Andreas Alfons
# 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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.