tlm {tlm} | R Documentation |
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 " |
family |
the link function. For linear model, |
data |
a |
ypow |
numeric power transformation already done in |
xpow |
numeric power transformation already done in |
type |
character indicating the type of plot for the fitted model. If " |
observed |
logical indicating whether the observations should be added to the plot. Assumed to be |
xname |
character. The name of the |
yname |
character. The name of the |
level |
numeric. Confidence level for the prediction of the measure of |
... |
further additional arguments passed to |
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.
Value
model |
the fitted model in the transformed space. |
ypow |
the value of |
xpow |
the value of |
Author(s)
Barrera-Gomez J and Basagana X.
References
Barrera-Gomez J, Basagana X. Models with transformed variables: interpretation and software. Epidemiology. 2015;26(2):e16-17.
See Also
Examples
### 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")