Movatterモバイル変換


[0]ホーム

URL:


Title:Effects under Linear, Logistic and Poisson Regression Modelswith Transformed Variables
Version:0.2.0
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>.
Depends:R (≥ 4.1)
Encoding:UTF-8
LazyData:true
Imports:graphics, stats, utils, boot
Suggests:knitr, rmarkdown, xtable
RoxygenNote:7.3.2
VignetteBuilder:knitr
License:GPL (≥ 3)
NeedsCompilation:no
Packaged:2025-01-07 10:20:59 UTC; jbarrera
Author:Jose Barrera-GomezORCID iD [aut, cre], Xavier BasaganaORCID iD [aut]
Maintainer:Jose Barrera-Gomez <jose.barrera@isglobal.org>
Repository:CRAN
Date/Publication:2025-01-07 11:10:02 UTC

tlm: 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.

Author(s)

Maintainer: Jose Barrera-Gomezjose.barrera@isglobal.org (ORCID)

Authors:


Expected Adjusted Median or Generalized Mean

Description

Computes expected measures of the response variable under a linear,logistic or Poisson regression fitted model with transformed variables. Measurescan be reported in both the original and the transformed space. The functionautomatically provides the name of the measure depending on the fitted model.

Usage

MY(  object,  x = NULL,  npoints = 10,  space = c("original", "transformed"),  level = 0.95)## S3 method for class 'MY'print(x, ...)

Arguments

object

object of classtlm, a result of a call totlm.

x

ForMY, a number or a numeric vector containing the values ofthe explanatory variable of interest for which the expected measure of theresponse variable are required. Default isNULL. Forprint.MY, anobject of class "MY" (an output of theMY function).

npoints

numeric. Ifx isNULL, the number of points wherethe measure should be measured. Default is 10. See Details below.

space

character. If "original" (default), the measure is reportedin the original space of the variables. If "transformed", the measureis reported in the transformed space of the variables, where the model is fitted.

level

numeric. The confidence level for measures. Default is 0.95.

...

additional arguments forprint.MY.

Details

In order to compute adjusted measures, all explanatory variables inthe model different than the explanatory variable of interest are set at theirmeans.

Ifspace is "original", then the mean (for Poisson response) orthe probability (for binary response) is computed. For gaussian response, themean is computed if the response variable is not transformed; otherwise, thegeometric mean (for log transformation in the response) or the median (forpower transformation) is computed.

Ifspace is "transformed", then the mean (for Poisson responseor transformed gaussian response), or the logodds (for binary response) iscomputed.

Ifx argument inMY isNULL, the measure is computed innpoints values of the explanatory variable of interest. Those valuesare chosen to be in arithmetic progression in the givenspace, insidethe observed range of the explanatory variable.

Value

A list with class "MY" including the following items:

M

adjusted measure of the response variable. See Details below.

ymeasure

the type of measure forM.

ypow

numeric power transformation assumed in the response variable.Seetlm.

xpow

numeric power transformation assumed in the explanatory variableof interest. Seetlm.

References

Barrera-Gomez J, Basagana X. Models with transformed variables:interpretation and software.Epidemiology. 2015;26(2):e16-17.

See Also

tlm,effectInfo,effect.

Examples

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")

Birth Weight and Cord Serum Cotinine

Description

Simulated data for birth weight and cord serum cotinine levels in351 newborns.

Usage

cotinine

Format

Adata.frame with 351 observations on the following 4 variables:

cotinine

cord serum cotinine level in the mother (ng/ml).

logcotinine

logarithm ofcotinine.

weight

birth weight (g).

underweight

a factor with levelsno andyes, indicatingunderweight (weight < 2500 g).

Details

Data were simulated to emulate true data pattern observed in a realstudy (see References).

Source

See References.

References

Pichini Set al. Cord serum cotinine as a biomarker of fetalexposure to cigarette smoke at the end of pregnancy.Environmental HealthPerspectives. 2000;108(11):1079-1083.

Examples

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))

Effects Estimate in Linear, Logistic and Poisson Regression Modelswith Transformed Variables

Description

Estimates the effect of a explanatory variable of interest on aresponse variable, under a fitted linear, logistic or Poisson regression modelwith transformed variables. The effect is reported in the original scale of thevariables.

Usage

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, ...)

Arguments

object

object of class "tlm", a result of a call totlm.

x1

numeric. The values of the explanatory variable where the effectshould be computed. See Details below.

x2

numeric. The alternative values of the explanatory variable(changing fromx1) for which the effect should be computed. SeeDetails below.

c

numeric. The additive change in the explanatory variable. See Detailsbelow.

q

numeric. The multiplicative change in the explanatory variable. SeeDetails below.

r

numeric. The percent change in the explanatory variable. See Detailsbelow.

npoints

numeric. The number of points where the effect should becomputed. 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 computeconfidence intervals. Default is 999. See Details below.

seed

numeric. A single value, the seed for bootstrapping. Default is4321.

verbose

logical. Whether to print detailed progress on R prompt.Default isTRUE.

x

forprint.effect, an object of class "effect" (an outputof theeffect function).

...

additional arguments forprint.effect.

Details

In order to compute the effect, both the initial and the final valuesof the explanatory should be provided. It can be done in several ways. Forinstance, providing,x1 andx2;x1 and one ofc,q orr;x1,npoints and one ofc,q orr. Only one of the argumentsc,q orr is used, prevailingc and thenq. If no enougharguments are passed, the interquartile range will be considered and asummary effect is computed, if it exists.

Confidence intervals are computed by transforming the endpoints of theintervals in the transformed scale when it is possible, while non-parametricbootstrap is used otherwise.

Value

A list with class "effect" including the following items:

effect

point estimate and confidence interval for the effect size.

info

information on how to interpret the effect. Used by the functioneffectInfo.

References

Barrera-Gomez J, Basagana X. Models with transformed variables:interpretation and software.Epidemiology. 2015;26(2):e16-17.

See Also

tlm,effectInfo,MY.

Examples

### 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)

Interpretation of Effects in Linear, Logistic and Poisson Models withTransformed Variables

Description

Provides information on interpreting effects in linear, logisticand Poisson models with transformed variables. Specifically, if a summarymeasure for the effect exists, the function details how to obtain and interpret it.

Usage

effectInfo(object)## S3 method for class 'effectInfo'print(x, ...)

Arguments

object

object of class "tlm" obtained with the functiontlm.

x

forprint.effectInfo, an object of class "effectInfo" (an outputof theeffectInfo function).

...

additional arguments forprint.effectInfo.

Value

A list with class "effectInfo" including the following items:

beta

regression coefficient estimate in the fitted model which isassociated to the effect of the explanatory variable of interest on theresponse variable.NA corresponds to those models for which asummary effect does not exist.

Xincrease

type of change in the exploratory variable of interest(additive or realtive) for which a summary effect exists.NAcorresponds to those models for which a summary effect does not exist.

effecttype

type of effect on the response variable for which asummary effect exists.NA corresponds to those models for which asummary effect is not available.

effectsize

formula for the summary effect size, if any.NAcorresponds to those models for which a summary effect is not available.

furtherinfo

further information about how to interpret effects.

References

Barrera-Gomez J, Basagana X. Models with transformed variables:interpretation and software.Epidemiology. 2015;26(2):e16-17.

See Also

tlm,effect,MY.

Examples

### 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)modglucoeffectInfo(modgluco)

Cat Allergen Concentrations

Description

Simulated data for cat allergen concentrations (Fel d 1) in 471homes, measured in both the living room and the bed mattress.

Usage

feld1

Format

Adata.frame with 471 observations on the following 5 variables:

mattress

Feld d 1 concentration in the bed mattress (\mug/g).

room

Feld d 1 concentration in the living room (\mug/g).

logmattress

logarithm ofmattress.

logroom

logarithm ofroom.

cat

a factor with levelsno andyes, indicating cat ownership.

Details

Data were simulated to emulate true data pattern observed in a realstudy (see References).

Source

See References.

References

Basagana Xet al. Domestic aeroallergen levels in Barcelonaand Menorca (Spain).Pediatric Allergy and Immunology. 2002;13(6):412-417.

Examples

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)))

Glucose and Triglycerides Levels in Blood

Description

Simulated data for glucose and triglycerides levels in blood in400 adults.

Usage

glucose

Format

Adata.frame with 400 observations on the following 4 variables:

trigly

triglycerides levels in blood (mg/dl).

gluco

glucose levels in blood (mg/dl).

inv12tri

numeric. Reciprocal of the square root oftrigly (i.e., -1/2 power transformation).

inv2glu

numeric. Reciprocal of thegluco square (i.e., -2 power transformation).

Details

Data were simulated to emulate true data pattern observed in a realstudy (see References).

Source

See References.

References

Rivera Met al. Association between long-term exposure totraffic-related air pollution and subclinical atherosclerosis: the REGICORStudy.Environmental Health Perspectives. 2013;121(2):223-230.

Examples

data(glucose)par(las = 1, mfrow = c(1, 2))with(glucose, plot(trigly, gluco))with(glucose, plot(inv12tri, inv2glu))

Intima Media Thickness of the Carotid Artery

Description

Simulated data for intima media thickness of the carotid arteryand age in 2784 adults.

Usage

imt

Format

Adata.frame with 2784 observations on the following 3 variables:

age

age of the individual (years).

imt

intima media thickness of the carotid artery (mm).

logimt

logarithm ofimt.

Details

Data were simulated to emulate true data pattern observed in a realstudy (see References).

Source

See References.

References

Rivera Met al. Association between long-term exposure totraffic-related air pollution and subclinical atherosclerosis: the REGICORStudy.Environmental Health Perspectives. 2013;121(2):223-230.

Examples

data(imt)par(las = 1, mfrow = c(1, 2))with(imt, plot(age, imt))with(imt, plot(age, logimt))

Summarizing the Model Fitting

Description

Asummary method for an object created by the functiontlm.

Usage

## S3 method for class 'tlm'summary(object, ...)## S3 method for class 'summary.tlm'print(x, ...)

Arguments

object

an object of class "tlm", an output of thetlmfunction.

...

additional arguments.

x

an object of class "summary.tlm" (an output ofsummary.tlm).

Details

Essentially, the output ofsummary.lm orsummary.glmis displayed. In addition, further information on the fitted model is alsodisplayed.

Value

A list with class "summary.tlm" including the following items:

model

the fitted model in the transformed space.

ypow

the value ofypow.

xpow

the value ofxpow.

summary

the summary of the fitted model provide bysummary.lm(for gaussian response) orsummary.glm (otherwise).

References

Barrera-Gomez J, Basagana X. Models with transformed variables:interpretation and software. Epidemiology. 2015;26(2):e16-17.

See Also

tlm,effectInfo,MY.

Examples

### linear model with log-log transformation:data(feld1)modcat <- tlm(logroom ~ logmattress + cat, data = feld1, ypow = 0, xpow = 0)modcatsummary(modcat)

Fitting, Reporting and Visualizing Linear, Logistic and PoissonRegression Models with Transformed Variables

Description

tlm is the main function of the package. It fits a linear,logistic or Poisson regression model with transformed variables and createsan object which can be subsequently used to compute adjusted measures of theresponse variable (withMY) and compute and interpret adjustedeffects of the explanatory variable of interest on the response variable (witheffect andeffectInfo, respectively), in the naturalscale of the variables. In addition, the fitted model can be visualized withtheplot.tlm method.

Usage

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, ...)

Arguments

formula

modelformula. Left-hand-side indicates the responsevariable (whose values are assumed to be already transformed). First term inright-hand-side indicates the explanatory variable of interest (whose valuesare assumed to be already transformed). Right-hand-side can include additionalterms (e.g. adjusting variables) but the explanatory variable of interestcannot be involved in any of them.

family

the response variablefamily. Allowed values are: 1)gaussian(default), for linear regression; 2)binomial, for logistic regression,and 3)poisson, for Poisson regression with logarithmic link. Quotedvalues are allowed.

data

adata.frame containing the variables in the model.

ypow

numeric. Power transformation already done in the response variable.See Details below.

xpow

numeric. Power transformation already done in the explanatoryvariable of interest. See Details below.

...

fortlm, additional arguments for the underlyinglmorglm fitting. Forprint.tlm andplot.tlm, additionalarguments for generic methodsprint andplot, respectively.

y,z

old arguments for back compatibility only. To be removed, seeDetails below.

x

fortlm, old argument for back compatibility only. To beremoved, see Details below. Forprint.tlm andplot.tlm, anobject of class "tlm" (an output of thetlm function).

type

Forplot.tlm, character indicating the type of plot forthe fitted model. If "original" (default), the fitted model is plottedin the original space of the variables. If "diagnosis", a modeldiagnostics plot is shown. If "transformed", the fitted model isplotted in the transformed space of the variables (where the modelhas been fitted). Resulting plots under "transformed" should not bereported (see Details below).

observed

Forplot.tlm, logical indicating whether the observationsare shown in the plot. Assumed to beFALSE if the explanatory variableof interest is categorical. Default isFALSE.

xname,yname

Forplot.tlm, character indicating the name of theexplanatory and the response variable of interest for labeling the plot axes.Default are "x" and "y", respectively.

level

Forplot.tlm, numeric indicating the confidence level forthe confidence of the expectation of the response variable according to thefitted model. Default is 0.95.

Details

The transformations already done in the response variable and in theexplanatory variable of interest are passed byypow andxpow,respectively, and must be numbers. Default is 1, meaning no transformation.The value 0 corresponds to the logarithmic transformation. Iffamilyis notgaussian, the response variable is assumed non transformed. Ifthe explanatory variable of interest is categorical or takes only two differentvalues, the value ofxpow is assumed to be 1. If the explanatoryvariable of interest takes only two different values, it is handled as abinary variable.

Plots obtained fortype = "transformed" are intended to visually explorethe model goodness of fit and should not be reported because values of thetransformed variables are meaningless (e.g. log(cotinine) has no sense).

Old argumentsy,x andz, are deprecated and bugs areno longer fixed. They will be removed in the first version posterior to 0.2.0.Use argumentformula instead.

Value

A list with class "tlm" including the following items:

model

the fitted model in the transformed space.

ypow

the value ofypow.

xpow

the value ofxpow.

References

Barrera-Gomez J, Basagana X. Models with transformed variables:interpretation and software.Epidemiology. 2015;26(2):e16-17.

See Also

MY,effect,formula.

Examples

### 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)modcatsummary(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")

[8]ページ先頭

©2009-2025 Movatter.jp