tlm: Fitting, Reporting and Visualizing Linear, Logistic and...

View source: R/tlm.R

tlmR Documentation

Fitting, Reporting and Visualizing Linear, Logistic and Poisson Regression 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 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.

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

model formula. Left-hand-side indicates the response variable (whose values are assumed to be already transformed). First term in right-hand-side indicates the explanatory variable of interest (whose values are assumed to be already transformed). Right-hand-side can include additional terms (e.g. adjusting variables) but the explanatory variable of interest cannot be involved in any of them.

family

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

data

a data.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 explanatory variable of interest. See Details below.

...

for tlm, additional arguments for the underlying lm or glm fitting. For print.tlm and plot.tlm, additional arguments for generic methods print and plot, respectively.

y, z

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

x

for tlm, old argument for back compatibility only. To be removed, see Details below. For print.tlm and plot.tlm, an object of class "tlm" (an output of the tlm function).

type

For plot.tlm, character indicating the type of plot for the fitted model. If "original" (default), the fitted model is plotted in the original space of the variables. If "diagnosis", a model diagnostics plot is shown. If "transformed", the fitted model is plotted in the transformed space of the variables (where the model has been fitted). Resulting plots under "transformed" should not be reported (see Details below).

observed

For plot.tlm, logical indicating whether the observations are shown in the plot. Assumed to be FALSE if the explanatory variable of interest is categorical. Default is FALSE.

xname, yname

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

level

For plot.tlm, numeric indicating the confidence level for the confidence of the expectation of the response variable according to the fitted model. Default is 0.95.

Details

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.

Value

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

model

the fitted model in the transformed space.

ypow

the value of ypow.

xpow

the value of xpow.

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

tlm documentation built on April 4, 2025, 1:06 a.m.