Create the needed information to perform transformations of the response variable, including inverting the transformation and estimating variances of back-transformed predictions via the delta method. make.tran
is similar to make.link
, but it covers additional transformations. The result can be used as an environment in which the model is fitted, or as the tran
argument in update.ref.grid
(when the given transformation was already applied in an existing model).
make.tran(type = c("genlog", "power", "boxcox", "sympower", "asin.sqrt"), param = 1)# See Details for additional auto-detected transformations
The name of the transformation. See Details.
Numeric parameter for the transformation. Optionally, it may be a vector of two numeric values; the second element specifies an alternative base or origin for certain transformations. See Details.
A list
having at least the same elements as that returned by make.link
. The linkfun
component is the transformation itself.
The functions lsmeans
, ref.grid
, and related ones automatically detect response transformations that are recognized by examining the model formula. These are log
, log2
, log10
, sqrt
, logit
, probit
, cauchit
, cloglog
; as well as (for a response variable y
) asin(sqrt(y))
, asinh(sqrt(y))
, and sqrt(y) + sqrt(y+1)
. In addition, any constant multiple of these (e.g., 2*sqrt(y)
) is auto-detected and appropriately scaled (see also the tran.mult
argument in update.ref.grid
).
A few additional character strings may be supplied as the tran
argument in update.ref.grid
: "identity"
, "1/mu^2"
, "inverse"
, "reciprocal"
, "asin.sqrt"
, and "asinh.sqrt"
.
More general transformations may be provided as a list of functions and supplied as the tran
argument as documented in update.ref.grid
. The make.tran
function returns a suitable list of functions for several popular transformations. Besides being usable with update
, the user may use this list as an enclosing environment in fitting the model itself, in which case the transformation is auto-detected when the special name linkfun
(the transformation itself) is used as the response transformation in the call. See the examples below.
Most of the transformations available in "make.tran" require a parameter, specified in param
; we use \(p\) to denote this parameter, and \(y\) to denote the response variable, in subsequent expressions.
The type
argument specifies the following transformations:
"genlog"
Generalized logarithmic transformation: \(log(y + p)\), where \(y > -p\)
"power"
Power transformation: \(y^p\), where \(y > 0\). When \(p = 0\), "log"
is used instead
"boxcox"
The Box-Cox transformation (unscaled by the geometric mean): \((y^p - 1) / p\), where \(y > 0\). When \(p = 0\), \(log(y)\) is used.
"sympower"
A symmetrized power transformation on the whole real line: \(abs(y)^p * sign(y)\). There are no restrictions on \(y\), but we require \(p > 0\) in order for the transformation to be monotone and continuous.
"asin.sqrt"
Arcsin-square-root transformation: \(sin^(-1)(y/p)^{1/2)}. Typically, the parameter \eqn{p} is equal to 1 for a fraction, or 100 for a percentage.\)
For purposes of back-transformation, the sqrt(y) + sqrt(y+1) transformation is treated exactly the same way as 2*sqrt(y), because both are regarded as estimates of 2\sqrt\mu.
# NOT RUN {
require("lsmeans")
# Fit a model using an oddball transformation:
bctran <- make.tran("boxcox", 0.368)
warp.bc <- with(bctran,
lm(linkfun(breaks) ~ wool * tension, data = warpbreaks))
# Obtain back-transformed LS means:
lsmeans(warp.bc, ~ tension | wool, type = "response")
# }
# NOT RUN {
# An existing model 'mod' was fitted with a log(y + 1) transformation...
mod.rg <- update(ref.grid(mod), tran = make.tran("genlog", 1))
lsmeans(mod.rg, "treatment")
# }
Run the code above in your browser using DataLab