tlm: Fitting Linear, Logistic and Poisson Regression Models with...

Description Usage Arguments Details Value Author(s) References See Also Examples

View source: R/tlm.R

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

1
2
3
4
5
6
7
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". 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.

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

xpow

the value of xpow.

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

MY, effect, formula.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
### 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")

tlm documentation built on May 2, 2019, 2:11 p.m.