Learn R Programming

car (version 2.1-4)

skewPower: Skew Power Transformations

Description

Transform the elements of a vector using, the skew power transformations.

Usage

skewPower(U, lambda, jacobian.adjusted=FALSE, gamma)

# S3 method for skewpowerTransform contour(x, ksds = 4, levels = c(0.5, 0.95, 0.99, 0.999), main = "Skew Power Log-likelihood", ...) # S3 method for skewpowerTransformlmer contour(x, ksds = 4, levels = c(0.5, 0.95, 0.99, 0.999), main = "Skew Power Log-likelihood", ...)

Arguments

U

A vector, matrix or data.frame of values to be transformed

lambda

The one-dimensional transformation parameter, usually in the range from \(-2\) to \(2\), or if U is a matrix or data frame, a vector of length ncol(U) of transformation parameters

jacobian.adjusted

If TRUE, the transformation is normalized to have Jacobian equal to one. The default is FALSE.

gamma

The skew power family has two parameters, the power lambda, and the start gamma, which can be any positive value.

x

An object created by a call to powerTransform using the family="skewPower" option.

ksds

Contour plotting of the log-likelihood surface will cover plus of minus ksds standard deviations on each axis.

levels

Contours will be drawn at the values of levels. For example, levels=c(.5, .99) would display two contours, at the 50% level and at the 99% level.

main

Title for the contour plot

Additional arguments passed to the generic contour function.

Value

Returns a vector or matrix of transformed values. The contour method is used for the side-effect of drawing a contour plot.

Details

The skewPower family is a modification of the Box-Cox power family, see bcPower that allows the untransformed response to include negative values. Ignoring the Jacobian, correction, the Box-Cox family is defined to be \((U^{\lambda}-1)/\lambda\) for \(\lambda \neq 0\), and \(\log(U)\) if \(\lambda =0\). The skewPower family is the Box-Cox transformation of \(z = .5 * (U + (U^2 + \gamma^2)^{1/2})\). Zero or negative values for \(U\) are permitted if \(\gamma\) is positive.

If jacobian.adjusted is TRUE, then the transformed values are scaled to have Jacobian equal to 1, as suggested by Box and Cox (1964). This simplifies computing the maximum likelihood-like estimates of the transformation parameters.

Missing values are permitted, and return NA where ever U is equal to NA.

The contour method allows drawing a contour plot for the two-dimensional log-likelihood for the skew power parameters with a univariate response.

References

Fox, J. and Weisberg, S. (2011) An R Companion to Applied Regression, Second Edition, Sage.

Hawkins, D. and Weisberg, S. (2016) Combining the Box-Cox Power and Generalized Log Transformations to Accomodate Negative Responses In Linear and Mixed-Effects Linear Models, submitted for publication.

Weisberg, S. (2014) Applied Linear Regression, Fourth Edition, Wiley Wiley, Chapter 7.

See Also

powerTransform, bcPower, boxCox

Examples

Run this code
# Univariate Example, from Hawkins and Weisberg (2016)
m1 <- lm(I1L1 ~ pool, LoBD)
p1 <- powerTransform(m1, family="skewPower")
summary(p1)
# summary prints estimate, se and conf.ints for both parameters
# helper functions
c(p1$lambda, p1$gamma, LogLik=p1$llik)
vcov(p1) # Estimated covarinace from inverse Hessian
# tests are for lambda, maximizing over gamma (profile log-likelihoods
testTransform(p1, lambda=0.5)
# Contour plot of the log-likelihood
contour(p1, main="", levels=c(.5, .95, .99))
# the boxCox function can provide profile log-likelihoods for each of the two parameters:
boxCox(m1, family="skewPower", param="lambda", lambda=seq(0.25, 1.1, length=100))
boxCox(m1, family="skewPower", param="gamma", gamma=seq(3, 80, length=100))

# Fit with fixed gamma, in this case fixed at the estimate from p1
p2 <- powerTransform(m1, family="skewPower", gamma=p1$gamma)
# summary gives different tests because gamma is fixed rather than maximized over
summary(p2)

# Multivariate Response
p3 <- powerTransform(update(m1, as.matrix(cbind(LoBD$I1L2, LoBD$I1L1)) ~ .), 
     family="skewPower")
summary(p3)

# gamma fixed
p4 <- powerTransform(update(m1, as.matrix(cbind(LoBD$I1L2, LoBD$I1L1)) ~ .), 
     family="skewPower", gamma=p3$gamma)
summary(p4)

# mixed models fit with lmer - requires lmer and nloptr packages

data <- reshape(LoBD[1:20,], varying=names(LoBD)[-1], direction="long", v.names="y")
names(data) <- c("pool", "assay", "y", "id")
data$assay <- factor(data$assay)
require(lme4)
m2 <- lmer(y ~ pool + (1|assay), data)
f1 <- powerTransform(m2, family="skewPower")
summary(f1)
f2 <- powerTransform(m2, family="skewPower", gamma= 10)
summary(f2)

Run the code above in your browser using DataLab