Title: | Effects under Linear, Logistic and Poisson Regression Models with Transformed Variables |
---|---|
Description: | Computation of effects under linear, logistic and Poisson regression models with transformed variables. Logarithm and power transformations are allowed. Effects can be displayed both numerically and graphically in both the original and the transformed space of the variables. The methods are described in Barrera-Gomez and Basagana (2015) <doi:10.1097/EDE.0000000000000247>. |
Authors: | Jose Barrera-Gomez [aut, cre]
|
Maintainer: | Jose Barrera-Gomez <[email protected]> |
License: | GPL (>= 3) |
Version: | 0.2.0 |
Built: | 2025-02-06 06:13:51 UTC |
Source: | https://github.com/cran/tlm |
Simulated data for birth weight and cord serum cotinine levels in 351 newborns.
cotinine
cotinine
A data.frame
with 351 observations on the following 4 variables:
cord serum cotinine level in the mother (ng/ml).
logarithm of cotinine
.
birth weight (g).
a factor with levels no
and yes
, indicating
underweight (weight
< 2500 g).
Data were simulated to emulate true data pattern observed in a real study (see References).
See References.
Pichini S et al. Cord serum cotinine as a biomarker of fetal exposure to cigarette smoke at the end of pregnancy. Environmental Health Perspectives. 2000;108(11):1079-1083.
data(cotinine) par(las = 1, mfrow = c(2, 2)) with(cotinine, plot(cotinine, weight)) with(cotinine, plot(logcotinine, weight)) with(cotinine, boxplot(cotinine ~ underweight)) with(cotinine, boxplot(logcotinine ~ underweight))
data(cotinine) par(las = 1, mfrow = c(2, 2)) with(cotinine, plot(cotinine, weight)) with(cotinine, plot(logcotinine, weight)) with(cotinine, boxplot(cotinine ~ underweight)) with(cotinine, boxplot(logcotinine ~ underweight))
Estimates the effect of a explanatory variable of interest on a response variable, under a fitted linear, logistic or Poisson regression model with transformed variables. The effect is reported in the original scale of the variables.
effect( object, x1 = NULL, x2 = NULL, c = NULL, q = NULL, r = NULL, npoints = NULL, level = 0.95, nboot = 999, seed = 4321, verbose = TRUE ) ## S3 method for class 'effect' print(x, ...)
effect( object, x1 = NULL, x2 = NULL, c = NULL, q = NULL, r = NULL, npoints = NULL, level = 0.95, nboot = 999, seed = 4321, verbose = TRUE ) ## S3 method for class 'effect' print(x, ...)
object |
object of class " |
x1 |
numeric. The values of the explanatory variable where the effect should be computed. See Details below. |
x2 |
numeric. The alternative values of the explanatory variable
(changing from |
c |
numeric. The additive change in the explanatory variable. See Details below. |
q |
numeric. The multiplicative change in the explanatory variable. See Details below. |
r |
numeric. The percent change in the explanatory variable. See Details below. |
npoints |
numeric. The number of points where the effect should be computed. See Details below. |
level |
numeric. Confidence level for the effect estimate. Default is 0.95. |
nboot |
numeric. The number of non parametric bootstrap samples to compute confidence intervals. Default is 999. See Details below. |
seed |
numeric. A single value, the seed for bootstrapping. Default is 4321. |
verbose |
logical. Whether to print detailed progress on R prompt.
Default is |
x |
for |
... |
additional arguments for |
In order to compute the effect, both the initial and the final values
of the explanatory should be provided. It can be done in several ways. For
instance, providing, x1
and x2
; x1
and one of c
,
q
or r
; x1
, npoints
and one of c
,
q
or r
. Only one of the arguments c
, q
or
r
is used, prevailing c
and then q
. If no enough
arguments are passed, the interquartile range will be considered and a
summary effect is computed, if it exists.
Confidence intervals are computed by transforming the endpoints of the intervals in the transformed scale when it is possible, while non-parametric bootstrap is used otherwise.
A list with class "effect
" including the following items:
point estimate and confidence interval for the effect size.
information on how to interpret the effect. Used by the function
effectInfo
.
Barrera-Gomez J, Basagana X. Models with transformed variables: interpretation and software. Epidemiology. 2015;26(2):e16-17.
tlm
, effectInfo
, MY
.
### Linear model with log transformation in the response variable: data(imt) head(imt) # model fitting: modimt <- tlm(logimt ~ age, data = imt, ypow = 0) modimt # information on interpreting the effect: effectInfo(modimt) # the function effect provides as default the expected change in IMT # for an additive change in age equal to the interquartile range: effect(modimt) # other effects: (minage <- min(imt$age)) (maxage <- max(imt$age)) effect(modimt, c = maxage - minage) ## Not run: effect(modimt, x1 = minage, r = 50, npoints = 3) ## End(Not run)
### Linear model with log transformation in the response variable: data(imt) head(imt) # model fitting: modimt <- tlm(logimt ~ age, data = imt, ypow = 0) modimt # information on interpreting the effect: effectInfo(modimt) # the function effect provides as default the expected change in IMT # for an additive change in age equal to the interquartile range: effect(modimt) # other effects: (minage <- min(imt$age)) (maxage <- max(imt$age)) effect(modimt, c = maxage - minage) ## Not run: effect(modimt, x1 = minage, r = 50, npoints = 3) ## End(Not run)
Provides information on interpreting effects in linear, logistic and Poisson models with transformed variables. Specifically, if a summary measure for the effect exists, the function details how to obtain and interpret it.
effectInfo(object) ## S3 method for class 'effectInfo' print(x, ...)
effectInfo(object) ## S3 method for class 'effectInfo' print(x, ...)
object |
object of class " |
x |
for |
... |
additional arguments for |
A list with class "effectInfo
" including the following items:
regression coefficient estimate in the fitted model which is
associated to the effect of the explanatory variable of interest on the
response variable. NA
corresponds to those models for which a
summary effect does not exist.
type of change in the exploratory variable of interest
(additive or realtive) for which a summary effect exists. NA
corresponds to those models for which a summary effect does not exist.
type of effect on the response variable for which a
summary effect exists. NA
corresponds to those models for which a
summary effect is not available.
formula for the summary effect size, if any. NA
corresponds to those models for which a summary effect is not available.
further information about how to interpret effects.
Barrera-Gomez J, Basagana X. Models with transformed variables: interpretation and software. Epidemiology. 2015;26(2):e16-17.
### Linear model with log transformation in the explanatory variable: data(cotinine) head(cotinine) # model fitting: modcot <- tlm(weight ~ logcotinine, data = cotinine, xpow = 0) modcot # information on interpreting the effect: effectInfo(modcot) ### Linear model with no summary measure of effect: data(glucose) head(glucose) # transformations Y^(-2) and X^(-1/2): modgluco <- tlm(inv2glu ~ inv12tri, data = glucose, ypow = -2, xpow = -1/2) modgluco effectInfo(modgluco)
### Linear model with log transformation in the explanatory variable: data(cotinine) head(cotinine) # model fitting: modcot <- tlm(weight ~ logcotinine, data = cotinine, xpow = 0) modcot # information on interpreting the effect: effectInfo(modcot) ### Linear model with no summary measure of effect: data(glucose) head(glucose) # transformations Y^(-2) and X^(-1/2): modgluco <- tlm(inv2glu ~ inv12tri, data = glucose, ypow = -2, xpow = -1/2) modgluco effectInfo(modgluco)
Simulated data for cat allergen concentrations (Fel d 1) in 471 homes, measured in both the living room and the bed mattress.
feld1
feld1
A data.frame
with 471 observations on the following 5 variables:
Feld d 1 concentration in the bed mattress (g/g).
Feld d 1 concentration in the living room (g/g).
logarithm of mattress
.
logarithm of room
.
a factor with levels no
and yes
, indicating cat ownership.
Data were simulated to emulate true data pattern observed in a real study (see References).
See References.
Basagana X et al. Domestic aeroallergen levels in Barcelona and Menorca (Spain). Pediatric Allergy and Immunology. 2002;13(6):412-417.
data(feld1) par(las = 1, mfrow = c(1, 2)) with(feld1, plot(mattress, room, col = as.numeric(cat))) with(feld1, plot(logmattress, logroom, col = as.numeric(cat)))
data(feld1) par(las = 1, mfrow = c(1, 2)) with(feld1, plot(mattress, room, col = as.numeric(cat))) with(feld1, plot(logmattress, logroom, col = as.numeric(cat)))
Simulated data for glucose and triglycerides levels in blood in 400 adults.
glucose
glucose
A data.frame
with 400 observations on the following 4 variables:
triglycerides levels in blood (mg/dl).
glucose levels in blood (mg/dl).
numeric. Reciprocal of the square root of trigly
(i.e., -1/2 power transformation).
numeric. Reciprocal of the gluco
square (i.e., -2 power transformation).
Data were simulated to emulate true data pattern observed in a real study (see References).
See References.
Rivera M et al. Association between long-term exposure to traffic-related air pollution and subclinical atherosclerosis: the REGICOR Study. Environmental Health Perspectives. 2013;121(2):223-230.
data(glucose) par(las = 1, mfrow = c(1, 2)) with(glucose, plot(trigly, gluco)) with(glucose, plot(inv12tri, inv2glu))
data(glucose) par(las = 1, mfrow = c(1, 2)) with(glucose, plot(trigly, gluco)) with(glucose, plot(inv12tri, inv2glu))
Simulated data for intima media thickness of the carotid artery and age in 2784 adults.
imt
imt
A data.frame
with 2784 observations on the following 3 variables:
age of the individual (years).
intima media thickness of the carotid artery (mm).
logarithm of imt
.
Data were simulated to emulate true data pattern observed in a real study (see References).
See References.
Rivera M et al. Association between long-term exposure to traffic-related air pollution and subclinical atherosclerosis: the REGICOR Study. Environmental Health Perspectives. 2013;121(2):223-230.
data(imt) par(las = 1, mfrow = c(1, 2)) with(imt, plot(age, imt)) with(imt, plot(age, logimt))
data(imt) par(las = 1, mfrow = c(1, 2)) with(imt, plot(age, imt)) with(imt, plot(age, logimt))
Computes expected measures of the response variable under a linear, logistic or Poisson regression fitted model with transformed variables. Measures can be reported in both the original and the transformed space. The function automatically provides the name of the measure depending on the fitted model.
MY( object, x = NULL, npoints = 10, space = c("original", "transformed"), level = 0.95 ) ## S3 method for class 'MY' print(x, ...)
MY( object, x = NULL, npoints = 10, space = c("original", "transformed"), level = 0.95 ) ## S3 method for class 'MY' print(x, ...)
object |
object of class |
x |
For |
npoints |
numeric. If |
space |
character. If " |
level |
numeric. The confidence level for measures. Default is 0.95. |
... |
additional arguments for |
In order to compute adjusted measures, all explanatory variables in the model different than the explanatory variable of interest are set at their means.
If space
is "original
", then the mean (for Poisson response) or
the probability (for binary response) is computed. For gaussian response, the
mean is computed if the response variable is not transformed; otherwise, the
geometric mean (for log transformation in the response) or the median (for
power transformation) is computed.
If space
is "transformed
", then the mean (for Poisson response
or transformed gaussian response), or the logodds (for binary response) is
computed.
If x
argument in MY
is NULL
, the measure is computed in
npoints
values of the explanatory variable of interest. Those values
are chosen to be in arithmetic progression in the given space
, inside
the observed range of the explanatory variable.
A list with class "MY
" including the following items:
adjusted measure of the response variable. See Details below.
the type of measure for M
.
numeric power transformation assumed in the response variable.
See tlm
.
numeric power transformation assumed in the explanatory variable
of interest. See tlm
.
Barrera-Gomez J, Basagana X. Models with transformed variables: interpretation and software. Epidemiology. 2015;26(2):e16-17.
tlm
, effectInfo
, effect
.
data(feld1) head(feld1) # Linear model with log-log transformation, adjusting for variable 'cat': modcat <- tlm(logroom ~ logmattress + cat, data = feld1, ypow = 0, xpow = 0) summary(modcat) # Geometric mean of the response as a function of the explanatory variable, # adjusted for 'cat': MY(modcat) MY(modcat, npoints = 3) # computed at 1st and 3rd quartiles of the explanatory variable: MY(modcat, x = quantile(feld1$mattress, probs = c(1, 3)/4)) # Mean of the log(response) as a function of the log explanatory variable, # adjusted for 'cat': MY(modcat, space = "transformed")
data(feld1) head(feld1) # Linear model with log-log transformation, adjusting for variable 'cat': modcat <- tlm(logroom ~ logmattress + cat, data = feld1, ypow = 0, xpow = 0) summary(modcat) # Geometric mean of the response as a function of the explanatory variable, # adjusted for 'cat': MY(modcat) MY(modcat, npoints = 3) # computed at 1st and 3rd quartiles of the explanatory variable: MY(modcat, x = quantile(feld1$mattress, probs = c(1, 3)/4)) # Mean of the log(response) as a function of the log explanatory variable, # adjusted for 'cat': MY(modcat, space = "transformed")
A summary
method for an object created by the function tlm
.
## S3 method for class 'tlm' summary(object, ...) ## S3 method for class 'summary.tlm' print(x, ...)
## S3 method for class 'tlm' summary(object, ...) ## S3 method for class 'summary.tlm' print(x, ...)
object |
an object of class " |
... |
additional arguments. |
x |
an object of class " |
Essentially, the output of summary.lm
or summary.glm
is displayed. In addition, further information on the fitted model is also
displayed.
A list with class "summary.tlm
" including the following items:
the fitted model in the transformed space.
the value of ypow
.
the value of xpow
.
the summary of the fitted model provide by summary.lm
(for gaussian response) or summary.glm
(otherwise).
Barrera-Gomez J, Basagana X. Models with transformed variables: interpretation and software. Epidemiology. 2015;26(2):e16-17.
tlm
, effectInfo
, MY
.
### linear model with log-log transformation: data(feld1) modcat <- tlm(logroom ~ logmattress + cat, data = feld1, ypow = 0, xpow = 0) modcat summary(modcat)
### linear model with log-log transformation: data(feld1) modcat <- tlm(logroom ~ logmattress + cat, data = feld1, ypow = 0, xpow = 0) modcat summary(modcat)
tlm
is the main function of the package. It fits a linear,
logistic or Poisson regression model with transformed variables and creates
an object which can be subsequently used to compute adjusted measures of the
response variable (with MY
) and compute and interpret adjusted
effects of the explanatory variable of interest on the response variable (with
effect
and effectInfo
, respectively), in the natural
scale of the variables. In addition, the fitted model can be visualized with
the plot.tlm
method.
tlm( formula, family = gaussian, data, ypow = 1, xpow = 1, ..., y, x, z = "none" ) ## S3 method for class 'tlm' print(x, ...) ## S3 method for class 'tlm' plot(x, type = c("original", "transformed", "diagnosis"), observed = FALSE, xname = "x", yname = "y", level = 0.95, ...)
tlm( formula, family = gaussian, data, ypow = 1, xpow = 1, ..., y, x, z = "none" ) ## S3 method for class 'tlm' print(x, ...) ## S3 method for class 'tlm' plot(x, type = c("original", "transformed", "diagnosis"), observed = FALSE, xname = "x", yname = "y", level = 0.95, ...)
formula |
model |
family |
the response variable |
data |
a |
ypow |
numeric. Power transformation already done in the response variable. See Details below. |
xpow |
numeric. Power transformation already done in the explanatory variable of interest. See Details below. |
... |
for |
y , z
|
old arguments for back compatibility only. To be removed, see Details below. |
x |
for |
type |
For |
observed |
For |
xname , yname
|
For |
level |
For |
The transformations already done in the response variable and in the
explanatory variable of interest are passed by ypow
and xpow
,
respectively, and must be numbers. Default is 1, meaning no transformation.
The value 0 corresponds to the logarithmic transformation. If family
is not gaussian
, the response variable is assumed non transformed. If
the explanatory variable of interest is categorical or takes only two different
values, the value of xpow
is assumed to be 1. If the explanatory
variable of interest takes only two different values, it is handled as a
binary variable.
Plots obtained for type = "transformed"
are intended to visually explore
the model goodness of fit and should not be reported because values of the
transformed variables are meaningless (e.g. log(cotinine) has no sense).
Old arguments y
, x
and z
, are deprecated and bugs are
no longer fixed. They will be removed in the first version posterior to 0.2.0.
Use argument formula
instead.
A list with class "tlm
" including the following items:
the fitted model in the transformed space.
the value of ypow
.
the value of xpow
.
Barrera-Gomez J, Basagana X. Models with transformed variables: interpretation and software. Epidemiology. 2015;26(2):e16-17.
### Linear model with log-log transformation: ### effect of mattress levels on room levels, adjusting for cat: # model fitting in the transformed space: data(feld1) head(feld1) modcat <- tlm(logroom ~ logmattress + cat, data = feld1, ypow = 0, xpow = 0) modcat summary(modcat) # plot of the geometric mean of the response (original space), adjusting for 'cat': plot(modcat, xname = "Mattress levels", yname = "room levels") # plot of the mean of the log of response (transformed space), adjusting for 'cat' and # adding the observations: plot(modcat, type = "transformed", xname = "mattress levels", yname = "room levels", observed = TRUE) # diagnosis plot: plot(modcat, type = "diagnosis") ### effect of cat in house on room levels, adjusting for matress levels: modcat2 <- tlm(logroom ~ cat + logmattress, data = feld1, ypow = 0) summary(modcat2) # plot of the geometric mean of the response (original space), adjusting # for mattress levels: plot(modcat2, xname = "Cat", yname = "room levels") # plot of the mean of the log of response (transformed space), adjusting # for mattress levels: plot(modcat2, type = "transformed", xname = "Cat", yname = "room levels")
### Linear model with log-log transformation: ### effect of mattress levels on room levels, adjusting for cat: # model fitting in the transformed space: data(feld1) head(feld1) modcat <- tlm(logroom ~ logmattress + cat, data = feld1, ypow = 0, xpow = 0) modcat summary(modcat) # plot of the geometric mean of the response (original space), adjusting for 'cat': plot(modcat, xname = "Mattress levels", yname = "room levels") # plot of the mean of the log of response (transformed space), adjusting for 'cat' and # adding the observations: plot(modcat, type = "transformed", xname = "mattress levels", yname = "room levels", observed = TRUE) # diagnosis plot: plot(modcat, type = "diagnosis") ### effect of cat in house on room levels, adjusting for matress levels: modcat2 <- tlm(logroom ~ cat + logmattress, data = feld1, ypow = 0) summary(modcat2) # plot of the geometric mean of the response (original space), adjusting # for mattress levels: plot(modcat2, xname = "Cat", yname = "room levels") # plot of the mean of the log of response (transformed space), adjusting # for mattress levels: plot(modcat2, type = "transformed", xname = "Cat", yname = "room levels")