Learn R Programming

alr3 (version 1.1.12)

inv.tran.plot: Choose a predictor transformation visually or numerically

Description

inv.tran.plot draws a two-dimensional scatterplot of $Y$ versus $X$, along with the OLS fit from the regression of $Y$ on $(X^{\lambda}-1)/\lambda$. inv.tran.estimate find the nonlinear least squares estimate of $\lambda$ and its standard error.

Usage

inv.tran.plot(x,y,lambda=c(-1,0,1),lty=1:(1+length(lambda)),
        col=rainbow(length(lambda)+1),xlab=deparse(substitute(x)),
        ylab=deparse(substitute(y)),family="box.cox",optimal=TRUE,
        key="topleft",...)

inv.tran.estimate(x,y,family="box.cox",...)

Arguments

x
The predictor variable
y
The response variable
lambda
The powers used in the plot. The optimal power than minimizes the residual sum of squares is always added unless optimal is FALSE.
family
The transformation family to use, "box.cox", "yeo.johnson", or a user-defined family.
optimal
Include the optimal value of lambda?
lty
line types corresponding to the powers
col
color corresponding to the powers
key
The default is "topleft", in which case a legend is added to the top left corner of the plot; other choices include "bottomright". If key is a vector of two coordinates, the legend is drawn at the coordinates spec
xlab
Label for the horizontal axis.
ylab
Label for the vertical axis.
...
additional arguments passed to other methods.

Value

  • inv.tran.plot returns a graph and a data.frame with $\lambda$ in the first column, and the residual sum of squares from the regression for that $\lambda$ in the second column. inv.tran.estimate returns a list with elements lambda for the estimate, se for its standard error, and RSS, the minimum value of the residual sum of squares.

References

Weisberg, S. (2005). Applied Linear Regression, third edition. New York: Wiley.

See Also

powtran, inverse.response.plot, optimize, nls

Examples

Run this code
data(baeskel)
attach(baeskel)
inv.tran.plot(Sulfur,Tension,key=c(.6,450))
ans <-inv.tran.estimate(Sulfur,Tension)
# redraw the plot, including the nls estimate
inv.tran.plot(Sulfur,Tension,lambda=c(ans$lambda,-1,0,1),key=c(.6,450))

Run the code above in your browser using DataLab