"boxcoxLm"
are returned by the boxcox
when the argument x
is an object
of class "lm"
. In this case, boxcox
computes
values of an objective function for user-specified powers, or computes the
optimal power for the specified objective, based on residuals from the linear model."boxcoxLm"
.optimize
component is FALSE
, then
lambda
contains the values of all of the powers at which the objective
was evaluated. If the value of the optimize
component is TRUE
,
then lambda
is a scalar containing the value of the power that
maximizes the objective.lambda
."PPCC"
(probability plot correlation coefficient; the default),
"Shapiro-Wilk"
(the Shapiro-Wilk goodness-of-fit statistic), and
"Log-Likelihood"
(the log-likelihood function).lambda
(optimize=FALSE
), or instead
the optimal power transformation was computed within the bounds specified by
lambda
(optimize=TRUE
).optimize=FALSE
, this contains
missing values.eps
was used.
When the absolute value of lambda
is less
than eps
, lambda is assumed to be 0 for the Box-Cox transformation.x
provided to boxcox
(an object that must inherit from class "lm"
)."boxcoxLm"
include:
link{plot}
, print
."boxcoxLm"
are lists that contain
information about the "lm"
object that was suplied,
the powers that were used, the objective that was used,
the values of the objective for the given powers, and whether an
optimization was specified.boxcox
, plot.boxcoxLm
, print.boxcoxLm
,
boxcox.object
.# Create an object of class "boxcoxLm", then print it out.
# The data frame Environmental.df contains daily measurements of
# ozone concentration, wind speed, temperature, and solar radiation
# in New York City for 153 consecutive days between May 1 and
# September 30, 1973. In this example, we'll plot ozone vs.
# temperature and look at the Q-Q plot of the residuals. Then
# we'll look at possible Box-Cox transformations. The "optimal" one
# based on the PPCC looks close to a log-transformation
# (i.e., lambda=0). The power that produces the largest PPCC is
# about 0.2, so a cube root (lambda=1/3) transformation might work too.
# Fit the model with the raw Ozone data
#--------------------------------------
ozone.fit <- lm(ozone ~ temperature, data = Environmental.df)
# Plot Ozone vs. Temperature, with fitted line
#---------------------------------------------
dev.new()
with(Environmental.df,
plot(temperature, ozone, xlab = "Temperature (degrees F)",
ylab = "Ozone (ppb)", main = "Ozone vs. Temperature"))
abline(ozone.fit)
# Look at the Q-Q Plot for the residuals
#---------------------------------------
dev.new()
qqPlot(ozone.fit$residuals, add.line = TRUE)
# Look at Box-Cox transformations of Ozone
#-----------------------------------------
boxcox.list <- boxcox(ozone.fit)
boxcox.list
#Results of Box-Cox Transformation
#---------------------------------
#
#Objective Name: PPCC
#
#Linear Model: ozone.fit
#
#Sample Size: 116
#
# lambda PPCC
# -2.0 0.4286781
# -1.5 0.4673544
# -1.0 0.5896132
# -0.5 0.8301458
# 0.0 0.9871519
# 0.5 0.9819825
# 1.0 0.9408694
# 1.5 0.8840770
# 2.0 0.8213675
#----------
# Clean up
#---------
rm(ozone.fit, boxcox.list)
Run the code above in your browser using DataLab