Learn R Programming

tlm (version 0.1.2)

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

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". For a single variable, the name of the variable (unquoted); for more than one variable, the names should be passed unquoted and separated by the plus sign; for all the remainin
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 th
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

  • modelthe fitted model in the transformed space.
  • ypowthe value of ypow.
  • xpowthe value of xpow.

Details

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.

References

Barrera-Gomez J, Basagana X. Interpretation of effects in linear, logistic and Poisson models with transformed variables: guidance for practice and software. (submitted).

See Also

MY, effect.

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 variable 'cat':
plot(modcat, xname = "Mattress levels", yname = "room levels") 
# plot of the mean of the log of response (transformed space), adjusting for variable '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