Title: | Visualization the Effects of Collinearity in Distributed Lag Models and Other Linear Models |
Version: | 0.0.4 |
Description: | Tool to assessing whether the results of a study could be influenced by collinearity. Simulations under a given hypothesized truth regarding effects of an exposure on the outcome are used and the resulting curves of lagged effects are visualized. A user's manual is provided, which includes detailed examples (e.g. a cohort study looking for windows of vulnerability to air pollution, a time series study examining the linear association of air pollution with hospital admissions, and a time series study examining the non-linear association between temperature and mortality). The methods are described in Basagana and Barrera-Gomez (2021) <doi:10.1093/ije/dyab179>. |
Depends: | R (≥ 4.1) |
License: | GPL-3 |
Encoding: | UTF-8 |
LazyData: | true |
Imports: | dlnm, graphics, grDevices, MASS, mgcv, nlme, stats, utils, VGAM |
Suggests: | knitr, rmarkdown, splines, xtable |
RoxygenNote: | 7.2.3 |
VignetteBuilder: | knitr |
NeedsCompilation: | no |
Packaged: | 2023-09-18 14:18:30 UTC; jbarrera |
Author: | Jose Barrera-Gomez
|
Maintainer: | Jose Barrera-Gomez <jose.barrera@isglobal.org> |
Repository: | CRAN |
Date/Publication: | 2023-09-19 09:00:06 UTC |
collin: Visualization the Effects of Collinearity in Distributed Lag Models and Other Linear Models
Description
Tool to assessing whether the results of a study could be influenced by collinearity. Simulations under a given hypothesized truth regarding effects of an exposure on the outcome are used and the resulting curves of lagged effects are visualized. A user's manual is provided, which includes detailed examples (e.g. a cohort study looking for windows of vulnerability to air pollution, a time series study examining the linear association of air pollution with hospital admissions, and a time series study examining the non-linear association between temperature and mortality). The methods are described in Basagana and Barrera-Gomez (2021) doi: 10.1093/ije/dyab179.
Author(s)
Maintainer: Jose Barrera-Gomez jose.barrera@isglobal.org (ORCID)
Authors:
Xavier Basagana xavier.basagana@isglobal.org (ORCID)
Simulates effects from a distributed lag model pattern.
Description
Simulates results from a distributed lag model under an hypothetical effect
pattern provided by the user, which can be linear or non-linear. The output
is the passed to the plot
method to visualize consequences of
collinearity.
Usage
collindlnm(
model,
x,
cb,
at = 1,
cen = 0,
effect,
type = c("coef", "risk"),
shape = c("linear", "nonlinear"),
nsim = 100,
verbose = TRUE,
seed = NULL
)
Arguments
model |
a model that includes a crossbasis. Currently, models allowed are those
of class |
x |
if |
cb |
an object of class |
at |
the increase(s) in the predictor under study to be considered to report the
effects of the variable. If |
cen |
a number. Reference value of the predictor under study, used to calculate
effects. If |
effect |
a vector or a matrix, depending on |
type |
a character. If |
shape |
the shape of the relationship between the linear predictor of the model
and the outcome. Default is |
nsim |
number of simulations. Default is 100. |
verbose |
a logical value indicating output status messages. Default is |
seed |
a number. Seed for reproducibility of results. Default is |
Value
A list including the results of the simulations to be passed to the plot
method.
See Also
crossbasis
, glm
,
lme
.
Examples
# For detailed examples:
browseVignettes("collin")
Function to get a vector lagged.
Description
Function to get a vector lagged.
Usage
lagpad(x, k)
Arguments
x |
numeric vector to be lagged. |
k |
number of lags to be applied. |
Value
A lagged vector.
Working memory test scores and air pollution.
Description
Simulated data for repeated measures of working memory test scores and
residential PM_{2.5}
levels in 2,221 children.
Usage
mempm25
Format
A data frame with 8,884 rows and 17 variables:
- id
individual identifier
- session
test session identifier
- school
chool identifier
- sex
sex of individual
- agecen
age of individual, centered at the mean, in years
- educ
maternal education
- resses
residential neighborhood socioeconomic status indicator
- pm25y0
estimated average concentration of PM
_{2.5}
(\mu
g/m^3
) at residence address during pregnancy- pm25y1
estimated average concentration of PM
_{2.5}
(\mu
g/m^3
) at residence address during year 1- pm25y2
estimated average concentration of PM
_{2.5}
(\mu
g/m^3
) at residence address during year 2- pm25y3
estimated average concentration of PM
_{2.5}
(\mu
g/m^3
) at residence address during year 3- pm25y4
estimated average concentration of PM
_{2.5}
(\mu
g/m^3
) at residence address during year 4- pm25y5
estimated average concentration of PM
_{2.5}
(\mu
g/m^3
) at residence address during year 5- pm25y6
estimated average concentration of PM
_{2.5}
(\mu
g/m^3
) at residence address during year 6- pm25y7
estimated average concentration of PM
_{2.5}
(\mu
g/m^3
) at residence address during year 7- wei
weight of the observation
- wmemo
working memory test score
Details
This is a synthetic dataset generated with the synthpop
package, based on
a cohort study of children examining the association between PM_{2.5}
concentrations during the prenatal period and the first seven postnatal years on
cognitive tests taken at age 8 (see ‘References’).
Source
See ‘References’.
References
Rivas I et al. Association between Early Life Exposure to Air Pollution and Working Memory and Attention. Environmental Health Perspectives. 2019;127(5):57002. doi: 10.1289/EHP3169.
Examples
# correlation of air pollution levels between two different periods:
pm25yearly <- mempm25[, grep("pm25", names(mempm25))]
print(cor(pm25yearly, use = "complete.obs"), digits = 2)
Visualizes effects of collinearity in distributed lag model under an hypothetical linear effect pattern.
Description
Visualize the results from a distributed lag model under an hypothetical
linear effect pattern provided by the user, generated using the function
collindlnm
.
Usage
## S3 method for class 'collindlnmlinear'
plot(x, lags = NULL, ...)
Arguments
x |
an object of class |
lags |
a number or a numeric vector indicating at what lags the results
will be visualized. Default ( |
... |
other parameters to be passed through to plot function. |
Value
A plot showing a comparison between the results under the fitted model and the results under the hypothetical true effect.
See Also
collindlnm
, plot.collindlnmnonlinear
.
Examples
# For detailed examples:
browseVignettes("collin")
Visualize effects of collinearity in distributed lag model under an hypothetical non-linear effect pattern.
Description
Visualize the results from a distributed lag model under an hypothetical
non-linear effect pattern provided by the user, generated using the function
collindlnm
. The number of plots shown is equal to the number
of values passed by at
in the function collindlnm
.
The way in which these plots are displayed is controlled by the user through
the argument show
.
Usage
## S3 method for class 'collindlnmnonlinear'
plot(
x,
lags = NULL,
show = c("manual", "auto", "sequence"),
addlegend = TRUE,
varlegend = NULL,
...
)
Arguments
x |
an object of class |
lags |
a number or a numeric vector indicating at what lags the results
will be visualized. Default ( |
show |
character indicating how the multiple plots will be shown. If
|
addlegend |
logical indicating whether a legend indicating at what
value (of |
varlegend |
character indicating the label for the explored variable to be shown in the legend. |
... |
other parameters to be passed through to plot function. |
Value
A plot showing a comparison between results under the fitted model and the results under the hypothetical true effect, for each of the different values of the variable of interest where effects were explored.
See Also
collindlnm
, plot.collindlnmlinear
.
Internal function to generate random numbers following over-dispersed Bernoulli distribution, based in the BetaBinomial distribution. It currently does not work and standard Bernoulli distribution is actually used instead.
Description
Internal function to generate random numbers following over-dispersed Bernoulli distribution, based in the BetaBinomial distribution. It currently does not work and standard Bernoulli distribution is actually used instead.
Usage
rbinomod(n, prob, d = 1)
Arguments
n |
integer. Number of observations. |
prob |
numeric. Probability of success on each trial. |
d |
numeric. Dispersion parameter. |
Value
a vector with the simulated sample.
Respiratory hospital admissions and air pollution.
Description
Simulated data for daily measures of hospital admissions for respiratory causes
count and ambient air NO_2
concentrations during 10 years.
Usage
rhospno2
Format
A data frame with 3,652 rows and 7 variables:
- date
date of the observation
- t
numerical indicator of date
- year
year indicator
- dow
day of week
- temp
ambient temperature in Celsius degrees
- no2
NO
_2
concentration in\mu
g/m^3
- hresp
number of hospital admissions for respiratory causes
Details
This is a synthetic dataset generated with the synthpop
package, based on
true data on daily number of hospital admissions for respiratory causes and
ambient air NO_2
concentrations in the city of Barcelona (Spain) for years
2006-2015.
Examples
# time series:
par(las = 1, mfrow = c(3, 1))
with(rhospno2, plot(date, hresp, type = "l", lwd = 0.5))
with(rhospno2, plot(date, no2, type = "l", lwd = 0.5))
with(rhospno2, plot(date, temp, type = "l", lwd = 0.5))
Internal function to generate random numbers following over-dispersed
Bernoulli or Poisson distribution. It wraps rpoisod
and
rbinomod
functions.
Description
Internal function to generate random numbers following over-dispersed
Bernoulli or Poisson distribution. It wraps rpoisod
and
rbinomod
functions.
Usage
rod(n, mu, d, type = c("binomial", "quasibinomial", "poisson", "quasipoisson"))
Arguments
n |
integer. Number of observations. |
mu |
numeric. Probability of success on each trial or mean, for (quasi)binomial and (quasi)Poisson, respectively. |
d |
numeric. Dispersion parameter. |
type |
character indicating the distribution. |
Value
a vector with the simulated sample.
Internal function to generate random numbers following over-dispersed Poisson distribution based on simple cheat of using a standard negative binomial, but choosing the scale parameter to give the desired mean vs variance ratio at the given value of the mean. Taken from: https://stat.ethz.ch/pipermail/r-help/2002-June/022425.html
Description
Internal function to generate random numbers following over-dispersed Poisson distribution based on simple cheat of using a standard negative binomial, but choosing the scale parameter to give the desired mean vs variance ratio at the given value of the mean. Taken from: https://stat.ethz.ch/pipermail/r-help/2002-June/022425.html
Usage
rpoisod(n, lambda, d = 1)
Arguments
n |
integer. Number of observations. |
lambda |
numeric. Mean. |
d |
numeric. Dispersion parameter. |
Value
a vector with the simulated sample.
simulatedllm generic.
Description
Simulation procedure internally called by the collindlnm
function for a given hypothetical effect.
Usage
simulatedlnm(x)
## S3 method for class 'linearlme'
simulatedlnm(x)
## S3 method for class 'linearglm'
simulatedlnm(x)
## S3 method for class 'nonlinearglm'
simulatedlnm(x)
Arguments
x |
an object internally generated by the |
Methods (by class)
-
simulatedlnm(linearlme)
: case of a hypothetical linear effect in a model of class"lme"
. -
simulatedlnm(linearglm)
: case of a hypothetical linear effect in a model of class"glm"
. -
simulatedlnm(nonlinearglm)
: case of a hypothetical non-linear effect in a model of class"glm"
.