Learn R Programming

tlm (version 0.1.5)

tlm: Fitting Linear, Logistic and Poisson Regression Models with Transformed Variables

Description

This function fits a linear, logistic or Poisson regression model with transformed variables and creates an object which can be used to extract effects of the explanatory variable of interest on the response variable, in the original scale of the variables.

Usage

tlm(y, x, z = "none", family = gaussian, data, ypow = 1, xpow = 1, ...)
# S3 method for tlm
print(x, ...)
# S3 method for tlm
plot(x, type = c("original", "transformed", "diagnosis"),
observed = FALSE,
                   xname = "x", yname = "y", level = 0.95, ...)

Arguments

y
name of the response variable (unquoted).
x
name of the explanatory variable of interest (unquoted).
z
additional explanatory variables in the model. Default is "none". See `Details'.
family
the link function. For linear model, gaussian (default); for logistic regression, binomial; for Poisson regression, poisson. Quoted values are optional. In the case of binomial, the logit link is assumed.
data
a data.frame containing the variables in the model.
ypow
numeric power transformation already done in y. See `Details'.
xpow
numeric power transformation already done in x. See `Details'.
type
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 "transformed", the fitted model is plotted in the transformed space of the variables (where the model has been fitted); if "diagnosis", a model diagnostics plot is shown.
observed
logical indicating whether the observations should be added to the plot. Assumed to be FALSE if x is categorical. Default is FALSE.
xname
character. The name of the x variable for labeling the horizontal plot axis. Default is "x".
yname
character. The name of the y variable for labeling the vertical plot axis. Default is "y". The name of the measure for the response variable is automatically added before yname.
level
numeric. Confidence level for the prediction of the measure of y plotted. Default is 0.95.
further additional arguments passed to tlm or methods print and plot.

Value

model
the fitted model in the transformed space.
ypow
the value of ypow.
xpow
the value of xpow.

Details

z can be any expression allowed as a right-hand-side in formula. However, expressions involving the variable passed in x are not allowed. To include all the remaining variables in data, use just a period (.). The transformations already done in y and x are passed by ypow and xpow, respectively. They should be a number. Default is 1 (no transformation). The value 0 corresponds to the logarithmic transformation. If family is not gaussian, y is assumed non transformed. If x is categorical or presents only two different values, the value of xpow is assumed to be 1. If x presents only two different values, it is considered as a binary variable.

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

Run this code
### Linear model with log-log transformation:
data(feld1)
head(feld1)
# model fitting in the transformed space:
modcat <-  tlm (y = logroom, x = logmattress, z = 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")

### The same model but now considering 'cat' as the explanatory variable of interest:
modcat2 <-  tlm (y = logroom, x = cat, z = 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")

Run the code above in your browser using DataLab