Title: | Estimation, Comparison and Selection of Transformations |
Version: | 1.0.1 |
Date: | 2018-11-26 |
Description: | Estimation, selection and comparison of several families of transformations. The families of transformations included in the package are the following: Bickel-Doksum (Bickel and Doksum 1981 <doi:10.2307/2287831>), Box-Cox, Dual (Yang 2006 <doi:10.1016/j.econlet.2006.01.011>), Glog (Durbin et al. 2002 <doi:10.1093/bioinformatics/18.suppl_1.S105>), gpower (Kelmansky et al. 2013 <doi:10.1515/sagmb-2012-0030>), Log, Log-shift opt (Feng et al. 2016 <doi:10.1002/sta4.104>), Manly, modulus (John and Draper 1980 <doi:10.2307/2986305>), Neglog (Whittaker et al. 2005 <doi:10.1111/j.1467-9876.2005.00520.x>), Reciprocal and Yeo-Johnson. The package simplifies to compare linear models with untransformed and transformed dependent variable as well as linear models where the dependent variable is transformed with different transformations. Furthermore, the package employs maximum likelihood approaches, moments optimization and divergence minimization to estimate the optimal transformation parameter. |
Depends: | R (≥ 3.2.4) |
License: | GPL-2 |
Encoding: | UTF-8 |
LazyData: | true |
RoxygenNote: | 6.1.1 |
Imports: | FNN, moments, pryr, graphics, grDevices, lmtest |
Suggests: | testthat, R.rsp |
VignetteBuilder: | R.rsp |
NeedsCompilation: | no |
Packaged: | 2018-11-27 14:53:57 UTC; akreutzmann |
Author: | Lily Medina [aut], Piedad Castro [aut], Ann-Kristin Kreutzmann [aut, cre], Natalia Rojas-Perilla [aut] |
Maintainer: | Ann-Kristin Kreutzmann <ann-kristin.kreutzmann@fu-berlin.de> |
Repository: | CRAN |
Date/Publication: | 2018-11-27 16:30:04 UTC |
An R package supporting the selection of a suitable transformation
Description
Estimation, selection and comparison of several families of transformations. The families of transformations included in the package are the following: Bickel-Doksum, Box-Cox, Dual, Glog, Gpower, Log, Log-shift opt, Manly, Modulus, Neglog, Reciprocal and Yeo-Johnson. The package simplifies to compare linear models with untransformed and transformed dependent variable as well as linear models where the dependent variable is transformed with different transformations. Furthermore, the package employs maximum likelihood approaches, skewness and divergence minimization to estimate the optimal transformation parameter.
Details
An overview of all currently provided functions can be requested by
library(help=trafo)
.
Maximum Likelihood
Description
Maximum Likelihood
Usage
ML(y, x, lambda, trafo, custom_func_std)
Arguments
y |
vector of response variables |
x |
matrix of regressors |
lambda |
transformation parameter |
trafo |
determines the chosen transformation |
custom_func_std |
a function that determines a customized standard transformation. |
Value
log-likelihood
Data frame with transformed variables
Description
The data frame that is returned contains the variables that are used in the model and additionally a variable with the transformed dependent variable. To the variable name of the dependent variable a t is added for transformed.
Usage
## S3 method for class 'trafo'
as.data.frame(x, row.names = NULL, optional = FALSE,
std = FALSE, ...)
Arguments
x |
an object of type |
row.names |
NULL or a character vector giving the row names for the data frame. Missing values are not allowed. |
optional |
logical. If TRUE, setting row names and converting column names (to syntactic names: see make.names) is optional. Note that all of R's base package as.data.frame() methods use optional only for column names treatment, basically with the meaning of data.frame(*, check.names = !optional) |
std |
logical. If |
... |
other parameters that can be passed to the function. |
Value
A data frame with the original variables and the transformed variable.
See Also
bickeldoksum
, boxcox
, dual
,
glog
, gpower
, log
,
logshiftopt
, manly
, modulus
,
neglog
, sqrtshift
, yeojohnson
Examples
# Load data
data("cars", package = "datasets")
# Fit linear model
lm_cars <- lm(dist ~ speed, data = cars)
# Transform dependent variable using divergence minimization following
# Kolmogorov-Smirnov
logshiftopt_trafo <- logshiftopt(object = lm_cars, method = "div.ks",
plotit = FALSE)
# Get a data frame with the added transformed variable
as.data.frame(logshiftopt_trafo)
First check of assumptions to find suitable transformations
Description
Gives a first overview if a transformation is useful and which transformation is promising to fulfill the model assumptions normality, homoscedasticity and linearity.
Usage
assumptions(object, method = "ml", std = FALSE, ...)
Arguments
object |
an object of type |
method |
a character string. Different estimation methods can be used for the estimation of the optimal transformation parameter: (i) Maximum likelihood approach ("ml"), (ii) Skewness minimization ("skew"), (iii) Kurtosis optimization ("kurt"), (iv) Divergence minimization by Kolmogorov-Smirnov ("div.ks"), by Cramer-von-Mises ("div.cvm") or by Kullback-Leibler ("div.kl"). Defaults to "ml". |
std |
logical. If |
... |
other parameters that can be passed to the function, e.g. other
lambdaranges. Self-defined lambdaranges are given to the function as an
argument that is the combination of the name of the transformation and lr and
the range needs to be a numeric vector of length 2. For instance, changing the
lambdarange for the Manly transformation would mean to add an argument
|
Value
A table with tests for normality and homoscedasticity. Furthermore, scatterplots are returned to check the linearity assumption.
See Also
bickeldoksum
, boxcox
, dual
,
glog
, gpower
, log
,
logshiftopt
, manly
, modulus
,
neglog
, sqrtshift
, yeojohnson
Examples
# Load data
data("cars", package = "datasets")
# Fit linear model
lm_cars <- lm(dist ~ speed, data = cars)
assumptions(lm_cars)
assumptions(lm_cars, method = "skew", manly_lr = c(0.000005,0.00005))
Bickel-Doksum transformation for linear models
Description
The function transforms the dependent variable of a linear model using the Bickel-Doksum transformation. The transformation parameter can either be estimated using different estimation methods or given.
Usage
bickeldoksum(object, lambda = "estim", method = "ml",
lambdarange = c(1e-11, 2), plotit = TRUE)
Arguments
object |
an object of type lm. |
lambda |
either a character named "estim" if the optimal transformation parameter should be estimated or a numeric value determining a given value for the transformation parameter. Defaults to "estim". |
method |
a character string. Different estimation methods can be used for the estimation of the optimal transformation parameter: (i) Maximum likelihood approach ("ml"), (ii) Skewness minimization ("skew"), (iii) Kurtosis optimization ("kurt"), (iv) Divergence minimization by Kolmogorov-Smirnov ("div.ks"), by Cramer-von-Mises ("div.cvm") or by Kullback-Leibler ("div.kl"). Defaults to "ml". |
lambdarange |
a numeric vector with two elements defining an interval
that is used for the estimation of the optimal transformation parameter.
The Bickel-Doksum transformation is only defined for positive values of
lambda. Defaults to |
plotit |
logical. If |
Value
An object of class trafo
. Methods such as
as.data.frame.trafo
and print.trafo
can
be used for this class.
References
Bickel PJ, Doksum KA (1981). An analysis of transformations revisited. Journal of the American Statistical Association, 76, 296-311.
Examples
# Load data
data("cars", package = "datasets")
# Fit linear model
lm_cars <- lm(dist ~ speed, data = cars)
# Transform dependent variable using a maximum likelihood approach
bickeldoksum(object = lm_cars, plotit = FALSE)
Box-Cox transformation for linear models
Description
The function transforms the dependent variable of a linear model using the Box-Cox transformation. The transformation parameter can either be estimated using different estimation methods or given. The Box-Cox transformation is only defined for positive response values. In case the response contains zero or negative values a shift is automatically added such that y + shift > 0.
Usage
boxcox(object, lambda = "estim", method = "ml", lambdarange = c(-2,
2), plotit = TRUE)
Arguments
object |
an object of type |
lambda |
either a character named "estim" if the optimal transformation parameter should be estimated or a numeric value determining a given value for the transformation parameter. Defaults to "estim". |
method |
a character string. Different estimation methods can be used for the estimation of the optimal transformation parameter: (i) Maximum likelihood approach ("ml"), (ii) Skewness minimization ("skew"), (iii) Kurtosis optimization ("kurt"), (iv) Divergence minimization by Kolmogorov-Smirnov ("div.ks"), by Cramer-von-Mises ("div.cvm") or by Kullback-Leibler ("div.kl"). Defaults to "ml". |
lambdarange |
a numeric vector with two elements defining an interval
that is used for the estimation of the optimal transformation parameter.
Defaults to |
plotit |
logical. If |
Value
An object of class trafo
. Methods such as
as.data.frame.trafo
and print.trafo
can
be used for this class.
References
Box GEP, Cox DR (1964). An Analysis of Transformations. Journal of the Royal Statistical Society B, 26(2), 211-252.
Examples
# Load data
data("cars", package = "datasets")
# Fit linear model
lm_cars <- lm(dist ~ speed, data = cars)
# Transform dependent variable using skewness minimization
boxcox(object = lm_cars, method = "skew", plotit = FALSE)
Box-Cox shift transformation for linear models
Description
The function transforms the dependent variable of a linear model using the Box-Cox shift transformation. The shift is not estimated but determined to the value min(y) + 1 in order to make all y positive. The transformation parameter can either be estimated using different estimation methods or given.
Usage
boxcoxshift(object, lambda = "estim", method = "ml",
lambdarange = c(-2, 2), plotit = TRUE)
Arguments
object |
an object of type lm. |
lambda |
either a character named "estim" if the optimal transformation parameter should be estimated or a numeric value determining a given value for the transformation parameter. Defaults to "estim". |
method |
a character string. Different estimation methods can be used for the estimation of the optimal transformation parameter: (i) Maximum likelihood approach ("ml"), (ii) Skewness minimization ("skew"), (iii) Kurtosis optimization ("kurt"), (iv) Divergence minimization by Kolmogorov-Smirnov ("div.ks"), by Cramer-von-Mises ("div.cvm") or by Kullback-Leibler ("div.kl"). Defaults to "ml". |
lambdarange |
a numeric vector with two elements defining an interval
that is used for the estimation of the optimal transformation parameter.
Defaults to |
plotit |
logical. If |
Value
an object of class trafo
.
References
Box GEP, Cox DR (1964). An Analysis of Transformations. Journal of the Royal Statistical Society B, 26(2), 211-252.
Diagnostics for fitted models
Description
Returns information about the transformation and selected diagnostics to check model assumptions.
Usage
diagnostics(object, ...)
Arguments
object |
an object that contains two models that should be compared. |
... |
other parameters that can be passed to the function. |
Value
The return depends on the class of its argument. The documentation of particular methods gives detailed information about the return of that method.
See Also
diagnostics.trafo_lm
,
diagnostics.trafo_compare
Diagnostics for two differently transformed models
Description
Returns information about the applied transformations and selected diagnostics to check model assumptions. Two models are compared where the dependent variable is transformed by different transformations.
Usage
## S3 method for class 'trafo_compare'
diagnostics(object, ...)
Arguments
object |
an object of type |
... |
additional arguments that are not used in this method |
Value
An object of class diagnostics.trafo_compare
. The method
print.diagnostics.trafo_compare
can be used for this class.
Examples
# Load data
data("cars", package = "datasets")
# Fit linear model
lm_cars <- lm(dist ~ speed, data = cars)
# Transform with Bickel-Doksum transformation
bd_trafo <- bickeldoksum(object = lm_cars, plotit = FALSE)
# Transform with Box-Cox transformation
bc_trafo <- boxcox(object = lm_cars, method = "skew", plotit = FALSE)
# Compare transformed models
compare <- trafo_compare(object = lm_cars, trafos = list(bd_trafo, bc_trafo))
# Get diagnostics
diagnostics(compare)
Diagnostics for an untransformed and a transformed model
Description
Returns information about the applied transformation and selected diagnostics to check model assumptions. The return helps to compare the untransformed and the transformed model with regard to model assumptions.
Usage
## S3 method for class 'trafo_lm'
diagnostics(object, ...)
Arguments
object |
an object of type |
... |
additional arguments that are not used in this method |
Value
An object of class diagnostics.trafo_lm
. The method
print.diagnostics.trafo_lm
can be used for this class.
Examples
# Load data
data("cars", package = "datasets")
# Fit linear model
lm_cars <- lm(dist ~ speed, data = cars)
# Compare transformed models
BD_lm <- trafo_lm(object = lm_cars, trafo = "bickeldoksum",
method = "skew", lambdarange = c(1e-11, 2))
# Get diagnostics
diagnostics(BD_lm)
Internal diagnostic functions
Description
The function is called in diagnostics.trafo_lm and diagnostics.trafo_compare.
Usage
diagnostics_internal(modOne, modTwo)
Divergence minimization by Cramer von Mises
Description
Divergence minimization by Cramer von Mises
Usage
divergence_min_CvM(res = res)
Arguments
res |
residuals from a linear model with response variable yt and explanatory variables x |
Value
sum of squared differences
Divergence minimization by Kullback-Leibler
Description
Divergence minimization by Kullback-Leibler
Usage
divergence_min_KL(res = res)
Arguments
res |
residuals from a linear model with response variable yt and explanatory variables x |
Value
median of Kullback-Leibler divergence
Divergence minimization by Kolmogorov Smirnov
Description
Divergence minimization by Kolmogorov Smirnov
Usage
divergence_min_KS(res = res)
Arguments
res |
residuals from a linear model with response variable yt and explanatory variables x |
Value
differences of supremum
Dual transformation for linear models
Description
The function transforms the dependent variable of a linear model using the Dual transformation. The transformation parameter can either be estimated using different estimation methods or given.
Usage
dual(object, lambda = "estim", method = "ml", lambdarange = c(0, 2),
plotit = TRUE)
Arguments
object |
an object of type lm. |
lambda |
either a character named "estim" if the optimal transformation parameter should be estimated or a numeric value determining a given value for the transformation parameter. Defaults to "estim". |
method |
a character string. Different estimation methods can be used for the estimation of the optimal transformation parameter: (i) Maximum likelihood approach ("ml"), (ii) Skewness minimization ("skew"), (iii) Kurtosis optimization ("kurt"), (iv) Divergence minimization by Kolmogorov-Smirnov ("div.ks"), by Cramer-von-Mises ("div.cvm") or by Kullback-Leibler ("div.kl"). Defaults to "ml". |
lambdarange |
a numeric vector with two elements defining an interval
that is used for the estimation of the optimal transformation parameter.
The Dual transformation is not defined for negative values of
lambda. Defaults to |
plotit |
logical. If |
Value
An object of class trafo
. Methods such as
as.data.frame.trafo
and print.trafo
can
be used for this class.
References
Yang Z (2006). A modified family of power transformations. Economics Letters, 92(1), 14-19.
Examples
# Load data
data("cars", package = "datasets")
# Fit linear model
lm_cars <- lm(dist ~ speed, data = cars)
# Transform dependent variable using divergence minimization following
# Cramer-von-Mises
dual(object = lm_cars, method = "div.cvm", plotit = TRUE)
Estimation of optimal transformation parameter - lm
Description
Estimation of optimal transformation parameter - lm
Usage
est_lm(y, x, method, lambdarange, trafo, custom_func, custom_func_std, ...)
Arguments
y |
vector of response variables |
x |
matrix of regressors |
method |
a character string. Different estimation methods can be used for the estimation of the optimal transformation parameter: (i) Maximum likelihood approach ("ml"), (ii) Skewness minimization ("skew"), (iii) Kurtosis optimization ("kurt"), (iv) Divergence minimization by Kolmogorov-Smirnov ("div.ks"), by Cramer-von-Mises ("div.cvm") or by Kullback-Leibler ("div.kl"). Defaults to "ml". |
lambdarange |
range for the estimation parameter expr(lambda) - default c(-2, 2) |
Value
modelt An object of type lm
employing the transformed vector yt
as the response variable
Box Cox Estimation - lme
Description
Box Cox Estimation - lme
Usage
est_lme(y, x, formula, data, rand_eff, method = method,
lambdarange = lambdarange, trafo, custom_func, custom_func_std)
Arguments
y |
vector of response variables |
x |
matrix of regressors |
method |
a character string. Different estimation methods can be used for the estimation of the optimal transformation parameter: (i) Restricted maximum likelihood approach ("reml"), (ii) Skewness minimization ("skew") and pooled skewness minimization ("pskew"), (iii) Divergence minimization by Kolmogorov-Smirnov ("div.ks"), by Cramer-von-Mises ("div.cvm") or by Kullback-Leibler ("div.kl"). |
lambdarange |
range for the estimation parameter expr(lambda) - default c(-2, 2) |
Value
modelt An object of type lm
employing the transformed vector yt
as the response variable
Wrapper function for estimation methods - linear models
Description
Wrapper function for estimation methods - linear models
Usage
estim_lm(lambda, y, x, method, trafo, custom_func, custom_func_std)
Arguments
lambda |
transformation parameter |
y |
vector of response variables |
x |
matrix of regressors |
method |
a character string. Different estimation methods can be used for the estimation of the optimal transformation parameter: (i) Maximum likelihood approach ("ml"), (ii) Skewness minimization ("skew"), (iii) Kurtosis optimization ("kurt"), (iv) Divergence minimization by Kolmogorov-Smirnov ("div.ks"), by Cramer-von-Mises ("div.cvm") or by Kullback-Leibler ("div.kl"). Defaults to "ml". In case of no and log transformation "NA" can be selected since no optimization is necessary for these two transformation types. |
trafo |
a character string that selects the transformation. |
custom_func |
a function that determines a customized transformation. |
custom_func_std |
a function that determines a customized standard transformation. |
Value
Depending on the selected method
the return is a log
likelihood, a skewness, a pooled skewness or a Kolmogorov-Smirnov, Cramer
von Mises or Kullback Leibler divergence.
Wrapper function for estimation methods - linear mixed models
Description
Wrapper function for estimation methods - linear mixed models
Usage
estim_lme(lambda, y, formula, data, rand_eff, method, trafo, custom_func,
custom_func_std)
Arguments
lambda |
transformation parameter |
y |
vector of response variables |
formula |
a formula object that contains the dependent and the explanatory measures |
data |
the data.frame that is given to function nlme and that contains the regression variables. |
rand_eff |
the random effect extracted from the lme object. |
method |
a character string. In order to determine the optimal parameter for the transformation five different estimation methods can be chosen (i) Maximum-Likelihood ("ml"); (ii) skewness minimization ("skew"); (iii) minimization of Kolmogorov-Smirnov divergence ("div.ks"); (iv) minimization of Cramer von Mises divergence ("div.cvm"); (v) minimization of Kullback Leibler divergence ("div.kl"). In case of no and log transformation "NA" can be selected since no optimization is necessary for these two transformation types. |
trafo |
a character string that selects the transformation. |
custom_func |
a function that determines a customized transformation. |
custom_func_std |
a function that determines a customized standard transformation. |
Value
Depending on the selected method
the return is a log
likelihood, a skewness, a pooled skewness or a Kolmogorov-Smirnov, Cramer
von Mises or Kullback Leibler divergence.
Function that fits model with transformed dependent variable
Description
Function that fits model with transformed dependent variable
Usage
get_modelt(object, trans_mod, std)
Arguments
object |
a model of type lm or lme |
trans_mod |
the return of one of the transformation functions |
std |
logical. If TRUE, the standardised transformations are used. |
Value
A lm or lme model that uses the transformed variable as dependent variable.
Function that bundles the return of a trafo object
Description
Function that bundles the return of a trafo object
Usage
get_transformed(trafo, ans, y, lambda, custom_func, custom_func_std,
custom_family)
Glog transformation for linear models
Description
The function transforms the dependent variable of a linear model using the Glog transformation.
Usage
glog(object)
Arguments
object |
an object of type lm. |
Value
An object of class trafo
. Methods such as
as.data.frame.trafo
and print.trafo
can
be used for this class.
References
Durbin BP, Hardin JS, Hawkins DM, Rocke DM (2002). A Variance-stabilizing Transformation for Gene-expression Microarray Data. Bioinformatics, 18, 105-110.
Examples
# Load data
data("cars", package = "datasets")
# Fit linear model
lm_cars <- lm(dist ~ speed, data = cars)
# Transform dependent variable
glog(object = lm_cars)
Gpower transformation for linear models
Description
The function transforms the dependent variable of a linear model using the Gpower transformation. The transformation parameter can either be estimated using different estimation methods or given.
Usage
gpower(object, lambda = "estim", method = "ml", lambdarange = c(-2,
2), plotit = TRUE)
Arguments
object |
an object of type lm. |
lambda |
either a character named "estim" if the optimal transformation parameter should be estimated or a numeric value determining a given value for the transformation parameter. Defaults to "estim". |
method |
a character string. Different estimation methods can be used for the estimation of the optimal transformation parameter: (i) Maximum likelihood approach ("ml"), (ii) Skewness minimization ("skew"), (iii) Kurtosis optimization ("kurt"), (iv) Divergence minimization by Kolmogorov-Smirnov ("div.ks"), by Cramer-von-Mises ("div.cvm") or by Kullback-Leibler ("div.kl"). Defaults to "ml". |
lambdarange |
a numeric vector with two elements defining an interval
that is used for the estimation of the optimal transformation parameter.
Defaults to |
plotit |
logical. If |
Value
An object of class trafo
. Methods such as
as.data.frame.trafo
and print.trafo
can
be used for this class.
References
Kelmansky DM, Martinez EJ, Leiva V (2013). A New Variance Stabilizing Transformation for Gene Expression Data Analysis. Statistical applications in genetics and molecular biology, 12(6), 653-666.
Examples
# Load data
data("cars", package = "datasets")
# Fit linear model
lm_cars <- lm(dist ~ speed, data = cars)
# Transform dependent variable using divergence minimization following
# Kullback-Leibler
gpower(object = lm_cars, method = "div.kl", plotit = FALSE)
Kurtosis
Description
Kurtosis
Usage
kurtosis_min(res = res)
Arguments
res |
residuals from a linear model with response variable yt and explanatory variables x |
Value
absolute value of the skewness of the residuals
Log shift transformation for linear models
Description
The function transforms the dependent variable of a linear model using the Log shift transformation. The shift parameter is determined by y + shift > 0.
Usage
logshift(object)
Arguments
object |
an object of type lm. |
Value
an object of class trafo
.
Log shift opt transformation for linear models
Description
The function transforms the dependent variable of a linear model using the Log shift opt transformation. The transformation parameter can either be estimated using different estimation methods or given.
Usage
logshiftopt(object, lambda = "estim", method = "ml",
lambdarange = NULL, plotit = TRUE)
Arguments
object |
an object of type lm. |
lambda |
either a character named "estim" if the optimal transformation parameter should be estimated or a numeric value determining a given value for the transformation parameter. Defaults to "estim". |
method |
a character string. Different estimation methods can be used for the estimation of the optimal transformation parameter: (i) Maximum likelihood approach ("ml"), (ii) Skewness minimization ("skew"), (iii) Kurtosis optimization ("kurt"), (iv) Divergence minimization by Kolmogorov-Smirnov ("div.ks"), by Cramer-von-Mises ("div.cvm") or by Kullback-Leibler ("div.kl"). Defaults to "ml". |
lambdarange |
a numeric vector with two elements defining an interval
that is used for the estimation of the optimal transformation parameter.
Defaults to |
plotit |
logical. If |
Value
An object of class trafo
. Methods such as
as.data.frame.trafo
and print.trafo
can
be used for this class.
Examples
# Load data
data("cars", package = "datasets")
# Fit linear model
lm_cars <- lm(dist ~ speed, data = cars)
# Transform dependent variable using divergence minimization following
# Kolmogorov-Smirnof
logshiftopt(object = lm_cars, method = "div.ks", plotit = FALSE)
Log transformation for linear models
Description
The function transforms the dependent variable of a linear model using the Log transformation. The Log transformation is only defined for positive response values. In case the response contains zero or negative values a shift is automatically added such that y + shift > 0.
Usage
logtrafo(object)
Arguments
object |
an object of type lm. |
Value
An object of class trafo
. Methods such as
as.data.frame.trafo
and print.trafo
can
be used for this class.
References
Box GEP, Cox DR (1964). An Analysis of Transformations. Journal of the Royal Statistical Society B, 26(2), 211-252.
Examples
# Load data
data("cars", package = "datasets")
# Fit linear model
lm_cars <- lm(dist ~ speed, data = cars)
# Transform dependent variable
logtrafo(object = lm_cars)
Manly transformation for linear models
Description
The function transforms the dependent variable of a linear model using the Manly transformation. The transformation parameter can either be estimated using different estimation methods or given.
Usage
manly(object, lambda = "estim", method = "ml", lambdarange = c(-2,
2), plotit = TRUE)
Arguments
object |
an object of type lm. |
lambda |
either a character named "estim" if the optimal transformation parameter should be estimated or a numeric value determining a given value for the transformation parameter. Defaults to "estim". |
method |
a character string. Different estimation methods can be used for the estimation of the optimal transformation parameter: (i) Maximum likelihood approach ("ml"), (ii) Skewness minimization ("skew"), (iii) Kurtosis optimization ("kurt"), (iv) Divergence minimization by Kolmogorov-Smirnov ("div.ks"), by Cramer-von-Mises ("div.cvm") or by Kullback-Leibler ("div.kl"). Defaults to "ml". |
lambdarange |
a numeric vector with two elements defining an interval
that is used for the estimation of the optimal transformation parameter.
Defaults to |
plotit |
logical. If |
Value
An object of class trafo
. Methods such as
as.data.frame.trafo
and print.trafo
can
be used for this class.
References
Manly BFJ (1976). Exponential data transformations. Journal of the Royal Statistical Society: Series D, 25, 37-42.
Examples
# Load data
data("cars", package = "datasets")
# Fit linear model
lm_cars <- lm(dist ~ speed, data = cars)
# Transform dependent variable using a maximum likelihood approach
manly(object = lm_cars, plotit = FALSE)
Modulus transformation for linear models
Description
The function transforms the dependent variable of a linear model using the Modulus transformation. The transformation parameter can either be estimated using different estimation methods or given.
Usage
modulus(object, lambda = "estim", method = "ml", lambdarange = c(-2,
2), plotit = TRUE)
Arguments
object |
an object of type lm. |
lambda |
either a character named "estim" if the optimal transformation parameter should be estimated or a numeric value determining a given value for the transformation parameter. Defaults to "estim". |
method |
a character string. Different estimation methods can be used for the estimation of the optimal transformation parameter: (i) Maximum likelihood approach ("ml"), (ii) Skewness minimization ("skew"), (iii) Kurtosis optimization ("kurt"), (iv) Divergence minimization by Kolmogorov-Smirnov ("div.ks"), by Cramer-von-Mises ("div.cvm") or by Kullback-Leibler ("div.kl"). Defaults to "ml". |
lambdarange |
a numeric vector with two elements defining an interval
that is used for the estimation of the optimal transformation parameter.
Defaults to |
plotit |
logical. If |
Value
An object of class trafo
. Methods such as
as.data.frame.trafo
and print.trafo
can
be used for this class.
References
John JA, Draper NR (1980). An alternative family of transformations. Journal of the Royal Statistical Society: Series C, 29, 190-197.
Examples
# Load data
data("cars", package = "datasets")
# Fit linear model
lm_cars <- lm(dist ~ speed, data = cars)
# Transform dependent variable with fixed lambda
modulus(object = lm_cars, lambda = 0.8, plotit = FALSE)
Neg log transformation for linear models
Description
The function transforms the dependent variable of a linear model using the Neg log transformation.
Usage
neglog(object)
Arguments
object |
an object of type lm. |
Value
An object of class trafo
. Methods such as
as.data.frame.trafo
and print.trafo
can
be used for this class.
References
Whittaker J, Whitehead C, Somers M (2005). The neglog transformation and quantile regression for the analysis of a large credit scoring database. Journal of the Royal Statistical Society. Series C (Applied Statistics), 54(4), 863-878.
Examples
# Load data
data("cars", package = "datasets")
# Fit linear model
lm_cars <- lm(dist ~ speed, data = cars)
# Transform dependent variable
neglog(object = lm_cars)
One parameter transformations
Description
Transforms the dependent variable of a regression model using one parameter transformations.
Usage
oneparam(object, ...)
Arguments
object |
an object of type lm or lme. |
... |
other parameters that can be passed to the function. |
Value
The return depends on the class of its argument. The documentation of particular methods gives detailed information about the return of that method.
See Also
One parameter transformations for linear models
Description
The function transforms the dependent variable of a linear model using the one parameter transformations. The transformation parameter can either be estimated using different estimation methods or given.
Usage
## S3 method for class 'lm'
oneparam(object, trafo, lambda = "estim", method = "ml",
lambdarange, plotit = TRUE, custom_trafo = NULL, ...)
Arguments
object |
an object of type lm. |
trafo |
character that determines the selected transformation. |
lambda |
either a character named "estim" if the optimal transformation parameter should be estimated or a numeric value determining a given transformation parameter. Defaults to "estim". |
method |
a character string. Different estimation methods can be used for the estimation of the optimal transformation parameter: (i) Maximum likelihood approach ("ml"), (ii) Skewness minimization ("skew"), (iii) Kurtosis optimization ("kurt"), (iv) Divergence minimization by Kolmogorov-Smirnov ("div.ks"), by Cramer-von-Mises ("div.cvm") or by Kullback-Leibler ("div.kl"). Defaults to "ml". |
lambdarange |
a numeric vector with two elements defining an interval
that is used for the estimation of the optimal transformation parameter.
Defaults to |
plotit |
logical. If |
custom_trafo |
a list that determines a one parameter transformation and the standardized one parameter transformation. |
... |
other parameters that can be passed to the function. |
Value
an object of class trafo
.
Plots for linear models with transformed dependent variable
Description
For the two transformed models a range of plots is returned in order to check model assumptions graphically.
Usage
## S3 method for class 'trafo_compare'
plot(x, ...)
Arguments
x |
an object of type |
... |
additional arguments that are not used in this method |
Plot for regression models with untransformed and transformed dependent variable
Description
For the untransformed and transformed model a range of plots is returned in order to check model assumptions graphically.
Usage
## S3 method for class 'trafo_lm'
plot(x, ...)
Arguments
x |
an object of type |
... |
additional arguments that are not used in this method |
Plot for optimal transformation parameter - linear models
Description
Plot for optimal transformation parameter - linear models
Usage
plot_trafolm(lambdarange, lambdaoptim, measoptim, y, x, trafo, method,
custom_func, custom_func_std)
Arguments
lambdarange |
a numeric vector with two elements defining an interval that is used for the estimation of the optimal transformation parameter. |
lambdaoptim |
optimal or given transformation parameter. |
measoptim |
measure at the optimal transformation parameter. |
y |
dependent variable. |
x |
matrix of regressors |
trafo |
a character string that selects the transformation. |
method |
a character string. Different estimation methods can be used for the estimation of the optimal transformation parameter: (i) Maximum likelihood approach ("ml"), (ii) Skewness minimization ("skew"), (iii) Kurtosis optimization ("kurt"), (iv) Divergence minimization by Kolmogorov-Smirnov ("div.ks"), by Cramer-von-Mises ("div.cvm") or by Kullback-Leibler ("div.kl"). Defaults to "ml". In case of no and log transformation "NA" can be selected since no optimization is necessary for these two transformation types. |
Prints diagnostics of two trafo objects
Description
Prints diagnostics of two trafo objects.
Usage
## S3 method for class 'diagnostics.trafo_compare'
print(x, ...)
Arguments
x |
an object of type |
... |
additional arguments that are not used in this method |
Prints diagnostics of an untransformed and a transformed model
Description
Prints diagnostics of an untransformed and a transformed model.
Usage
## S3 method for class 'diagnostics.trafo_lm'
print(x, ...)
Arguments
x |
an object of type |
... |
additional arguments that are not used in this method |
Prints summary of trafo_compare objects
Description
Prints objects to be shown in the summary function for objects of
type trafo_compare
.
Usage
## S3 method for class 'summary.trafo_compare'
print(x, ...)
Arguments
x |
an object of type |
... |
additional arguments that are not used in this method |
Print summary trafo
Description
prints objects to be shown in the summary function for objects of
type trafo_lm
Usage
## S3 method for class 'summary.trafo_lm'
print(x, ...)
Arguments
x |
an object of type |
... |
additional arguments that are not used in this method |
Prints object of type trafo
Description
Prints object of type trafo
Usage
## S3 method for class 'trafo'
print(x, ...)
Arguments
x |
an object of type |
... |
other parameters that can be passed to the function. |
Prints object of type trafo_compare
Description
Prints object of type trafo_compare
Usage
## S3 method for class 'trafo_compare'
print(x, ...)
Arguments
x |
an object of type trafo_compare. |
... |
other parameters that can be passed to the function. |
Prints object of type trafo_lm
Description
Prints object of type trafo_lm
Usage
## S3 method for class 'trafo_lm'
print(x, ...)
Arguments
x |
an object of type |
... |
other parameters that can be passed to the function. |
Reciprocal transformation for linear models
Description
The function transforms the dependent variable of a linear model using the Reciprocal transformation.
Usage
reciprocal(object)
Arguments
object |
an object of type lm. |
Value
An object of class trafo
. Methods such as
as.data.frame.trafo
and print.trafo
can
be used for this class.
Examples
# Load data
data("cars", package = "datasets")
# Fit linear model
lm_cars <- lm(dist ~ speed, data = cars)
# Transform dependent variable
reciprocal(object = lm_cars)
Skewness minimization by Molina
Description
Skewness minimization by Molina
Usage
skewness_min(res = res)
Arguments
res |
residuals from a linear model with response variable yt and explanatory variables x |
Value
absolute value of the skewness of the residuals
Square-root shift transformation for linear models
Description
The function transforms the dependent variable of a linear model using the Square-root shift transformation. The transformation parameter can either be estimated using different estimation methods or given.
Usage
sqrtshift(object, lambda = "estim", method = "ml",
lambdarange = NULL, plotit = TRUE)
Arguments
object |
an object of type lm. |
lambda |
either a character named "estim" if the optimal transformation parameter should be estimated or a numeric value determining a given value for the transformation parameter. Defaults to "estim". |
method |
a character string. Different estimation methods can be used for the estimation of the optimal transformation parameter: (i) Maximum likelihood approach ("ml"), (ii) Skewness minimization ("skew"), (iii) Kurtosis optimization ("kurt"), (iv) Divergence minimization by Kolmogorov-Smirnov ("div.ks"), by Cramer-von-Mises ("div.cvm") or by Kullback-Leibler ("div.kl"). Defaults to "ml". |
lambdarange |
a numeric vector with two elements defining an interval
that is used for the estimation of the optimal transformation parameter.
Defaults to |
plotit |
logical. If |
Value
An object of class trafo
. Methods such as
as.data.frame.trafo
and print.trafo
can
be used for this class.
Examples
# Load data
data("cars", package = "datasets")
# Fit linear model
lm_cars <- lm(dist ~ speed, data = cars)
# Transform dependent variable using a maximum likelihood approach
sqrtshift(object = lm_cars, plotit = TRUE)
Summary for two differently transformed models
Description
The summary contains the summary for two transformed models. The summary is
based on the summary for objects of type lm
.
Usage
## S3 method for class 'trafo_compare'
summary(object, ...)
Arguments
object |
an object of type |
... |
additional arguments that are not used in this method |
Value
An object of class summary.trafo_compare
. The method
print.summary.trafo_compare
can be used for this class.
Summary for linear models with untransformed and transformed dependent variable
Description
The summary method for class trafo_lm
contains a summary for an
untransformed and a transformed model. The resulting summary is based on the
summary for objects of type lm
.
Usage
## S3 method for class 'trafo_lm'
summary(object, ...)
Arguments
object |
an object of type |
... |
additional arguments that are not used in this method |
Value
An object of class summary.trafo_lm
. The method
print.summary.trafo_lm
can be used for this class.
Compares linear models with transformed dependent variable
Description
Function trafo_compare
compares linear models where the dependent
variable is transformed by different transformations.
Usage
trafo_compare(object, trafos, std = FALSE)
Arguments
object |
an object of type lm |
trafos |
a list of two |
std |
logical. If |
Value
An object of class trafo_compare
. Methods such as
diagnostics.trafo_compare
, print.trafo_compare
,
plot.trafo_compare
and summary.trafo_compare
can
be used for this class.
See Also
bickeldoksum
, boxcox
, dual
,
glog
, gpower
, log
,
logshiftopt
, manly
, modulus
,
neglog
, sqrtshift
, yeojohnson
Examples
# Load data
data("cars", package = "datasets")
# Fit linear model
lm_cars <- lm(dist ~ speed, data = cars)
# Transform with Bickel-Doksum transformation
bd_trafo <- bickeldoksum(object = lm_cars, plotit = FALSE)
# Transform with Box-Cox transformation
bc_trafo <- boxcox(object = lm_cars, method = "skew", plotit = FALSE)
# Compare transformed models
trafo_compare(object = lm_cars, trafos = list(bd_trafo, bc_trafo))
Fits transformed linear models
Description
Function trafo_lm
fits linear models with transformed dependent
variable. The main return are two lm
objects where one is the
untransformed linear model and the other one the transformed linear model.
Usage
trafo_lm(object, trafo = "boxcox", lambda = "estim", method = "ml",
lambdarange = NULL, std = FALSE, custom_trafo = NULL)
Arguments
object |
an object of type |
trafo |
a character string. Different transformations can be used for transforming the dependent variable in a linear model: (i) "bickeldoksum", (ii) "boxcox", (iii) "dual", (iv) "glog", (v) "gpower", (vi) "log", (vii) "logshiftopt", (viii) "manly", (ix) "modulus", (x) "neglog", (xi) "reciprocal", (xii) "yeojohnson". Defaults to "boxcox". |
lambda |
either a character named "estim" if the optimal transformation parameter should be estimated or a numeric value determining a given value for the transformation parameter. Defaults to "estim". |
method |
a character string. Different estimation methods can be used for the estimation of the optimal transformation parameter: (i) Maximum likelihood approach ("ml"), (ii) Skewness minimization ("skew"), (iii) Kurtosis optimization ("kurt"), (iv) Divergence minimization by Kolmogorov-Smirnov ("div.ks"), by Cramer-von-Mises ("div.cvm") or by Kullback-Leibler ("div.kl"). Defaults to "ml". |
lambdarange |
a numeric vector with two elements defining an interval
that is used for the estimation of the optimal transformation parameter.
Defaults to |
std |
logical. If |
custom_trafo |
a list. The list has two elements where the first element
is a function specifying the desired transformation and the second element is
a function specifying the corresponding standardized transformation.
Defaults to |
Value
An object of class trafo_lm
. Methods such as
diagnostics.trafo_lm
, print.trafo_lm
,
plot.trafo_lm
and summary.trafo_lm
can
be used for this class.
See Also
bickeldoksum
, boxcox
, dual
,
glog
, gpower
, log
,
logshiftopt
, manly
, modulus
,
neglog
, sqrtshift
, yeojohnson
Examples
# Load data
data("cars", package = "datasets")
# Fit linear model
lm_cars <- lm(dist ~ speed, data = cars)
# Compare untransformed and transformed model
trafo_lm(object = lm_cars, trafo = "bickeldoksum", method = "skew",
lambdarange = c(1e-11, 2))
Transformations without transformation parameter
Description
Transforms the dependent variable of a regression model using transformations without transformation parameter.
Usage
woparam(object, ...)
Arguments
object |
an object of type lm or lme. |
... |
other parameters that can be passed to the function. |
Value
The return depends on the class of its argument. The documentation of particular methods gives detailed information about the return of that method.
See Also
Transformations without parameter for linear models
Description
The function transforms the dependent variable of a linear model using different transformations without parameter.
Usage
## S3 method for class 'lm'
woparam(object, trafo, custom_trafo = NULL, ...)
Arguments
object |
an object of type lm. |
trafo |
character that determines the transformation. |
custom_trafo |
a function that specifies a transformation without parameter that needs to be estimated or given. |
... |
other parameters that can be passed to the function. |
Value
an object of class trafo
.
Yeo-Johnson transformation for linear models
Description
The function transforms the dependent variable of a linear model using the Yeo-Johnson transformation. The transformation parameter can either be estimated using different estimation methods or given.
Usage
yeojohnson(object, lambda = "estim", method = "ml",
lambdarange = c(-2, 2), plotit = TRUE)
Arguments
object |
an object of type lm. |
lambda |
either a character named "estim" if the optimal transformation parameter should be estimated or a numeric value determining a given value for the transformation parameter. Defaults to "estim". |
method |
a character string. Different estimation methods can be used for the estimation of the optimal transformation parameter: (i) Maximum likelihood approach ("ml"), (ii) Skewness minimization ("skew"), (iii) Kurtosis optimization ("kurt"), (iv) Divergence minimization by Kolmogorov-Smirnov ("div.ks"), by Cramer-von-Mises ("div.cvm") or by Kullback-Leibler ("div.kl"). Defaults to "ml". |
lambdarange |
a numeric vector with two elements defining an interval
that is used for the estimation of the optimal transformation parameter.
Defaults to |
plotit |
logical. If |
Value
An object of class trafo
. Methods such as
as.data.frame.trafo
and print.trafo
can
be used for this class.
References
Yeo IK, Johnson RA (2000). A new family of power transformations to improve normality or symmetry. Biometrika, 87, 954-959.
Examples
# Load data
data("cars", package = "datasets")
# Fit linear model
lm_cars <- lm(dist ~ speed, data = cars)
# Transform dependent variable using a maximum likelihood approach
yeojohnson(object = lm_cars, plotit = FALSE)