| Title: | Lagged Weighted Quantile Sum Regression |
|---|---|
| Description: | Wrapper functions for the implementation of lagged weighted quantile sum regression, as per 'Gennings et al' (2020) <doi:10.1016/j.envres.2020.109529>. |
| Authors: | Paul Curtin [aut, cre], Stefano Renzetti [aut], Chris Gennings [aut] |
| Maintainer: | Paul Curtin <[email protected]> |
| License: | GPL (>= 2) |
| Version: | 0.5.1 |
| Built: | 2026-10-17 08:42:52 UTC |
| Source: | https://github.com/cran/lwqs |
Function to extract time-varying mixture (wqs) index from lWQS object.
extract_mixture(lobj)extract_mixture(lobj)
lobj |
An object returned from the lwqs function. |
Data frame containing the time index, wqs index estimated at each repeated measure, subject ID, and the outcome variable.
## Not run: # identify predictor variables used in mixture mixvars=names(lwqs_data)[5:9] # run model. Note for example run-time only a small number of bootstraps # (b=5) is used; set b to be >50 in practice. model=lwqs(data=lwqs_data, timevar="time", wqs_parms=list(formula=out ~ wqs, data = lwqs_data, mix_name=mixvars, b_constr = TRUE, b1_pos=FALSE, b = 5, q = 5, validation = 0, family = "gaussian", seed = 1), outcome="out", ID="ID") # use extract_mixture to access time-varying wqs index mixtime=extract_mixture(model) ## End(Not run)## Not run: # identify predictor variables used in mixture mixvars=names(lwqs_data)[5:9] # run model. Note for example run-time only a small number of bootstraps # (b=5) is used; set b to be >50 in practice. model=lwqs(data=lwqs_data, timevar="time", wqs_parms=list(formula=out ~ wqs, data = lwqs_data, mix_name=mixvars, b_constr = TRUE, b1_pos=FALSE, b = 5, q = 5, validation = 0, family = "gaussian", seed = 1), outcome="out", ID="ID") # use extract_mixture to access time-varying wqs index mixtime=extract_mixture(model) ## End(Not run)
Function to extract time-varying weights from lWQS object.
extract_weights(lobj)extract_weights(lobj)
lobj |
An object returned from the lwqs function. |
A (long-form) data frame containing the time index and corresponding variable weights estimated in an lWQS.
## Not run: # identify predictor variables used in mixture mixvars=names(lwqs_data)[5:9] # run model model=lwqs(data=lwqs_data, timevar="time", wqs_parms=list(formula=out ~ wqs, data = lwqs_data, mix_name=mixvars, b_constr = TRUE, b1_pos=TRUE, b = 5, q = 5, validation = 0, family = "gaussian", seed = 1), outcome="out", ID="ID") # use extract_weights to access time-varying predictor weights timeweights=extract_weights(model) ## End(Not run)## Not run: # identify predictor variables used in mixture mixvars=names(lwqs_data)[5:9] # run model model=lwqs(data=lwqs_data, timevar="time", wqs_parms=list(formula=out ~ wqs, data = lwqs_data, mix_name=mixvars, b_constr = TRUE, b1_pos=TRUE, b = 5, q = 5, validation = 0, family = "gaussian", seed = 1), outcome="out", ID="ID") # use extract_weights to access time-varying predictor weights timeweights=extract_weights(model) ## End(Not run)
Wrapper function for the implementation of lagged WQS.
lwqs( data, timevar, wqs_parms, outcome, ID, rDLM_parms = list(formula = wqs ~ s(time, by = y, bs = "cr"), random = ~(1 | id)), ci_level = 0.95 )lwqs( data, timevar, wqs_parms, outcome, ID, rDLM_parms = list(formula = wqs ~ s(time, by = y, bs = "cr"), random = ~(1 | id)), ci_level = 0.95 )
data |
Data frame containing observations in long format. |
timevar |
Enquoted variable name identifying the repeated measure / time variable. |
wqs_parms |
A list containing parameters to be passed to the WQS algorithm. See gWQS package for details. |
outcome |
An enquoted variable name identifying the outcome measure. |
ID |
An enquoted variable name identifying the subject identifier. |
rDLM_parms |
(optional). A list containing parameters to be passed to the GAM algorithm. See gamm4 package for details. Parameters wqs, time, by, and id are created by the lwqs function and passed to the gamm4 function automatically. |
ci_level |
(optional). Confidence level for the time-varying effect band. Defaults to 0.95. |
The lwqs function returns a list containing final model output and time-specific model parameters.
parameters |
This list contains several objects summarizing different stages of the lagged ensemble model. The first
object, |
plot |
A combined plot (as a grob) summarizing the output of the lwqs algorithm. |
## Not run: # identify predictor variables used in mixture mixvars=names(lwqs_data)[5:9] # run model. model=lwqs(data=lwqs_data, timevar="time", wqs_parms=list(formula=out ~ wqs, data = lwqs_data, mix_name=mixvars, b_constr = TRUE, b1_pos=TRUE, b = 5, q = 5, validation = 0, family = "gaussian", seed = 1), outcome="out", ID="ID") ## End(Not run)## Not run: # identify predictor variables used in mixture mixvars=names(lwqs_data)[5:9] # run model. model=lwqs(data=lwqs_data, timevar="time", wqs_parms=list(formula=out ~ wqs, data = lwqs_data, mix_name=mixvars, b_constr = TRUE, b1_pos=TRUE, b = 5, q = 5, validation = 0, family = "gaussian", seed = 1), outcome="out", ID="ID") ## End(Not run)
Simulated dataset for accompanying vignette.
data(lwqs_data)data(lwqs_data)
A data frame containing simulated data to explore the lwqs algorithm. Variables included are as follows:
ID |
Variable identifying each simulated subject. Data reflect 30 successive measures per subject. |
Sex |
A simulated binary covariate, either 1 or 0. |
time |
Variable identifying the successive timing of each repeated measure. |
out |
Simulated outcome on standardized scale. |
pred1 |
First simulated time-varying predictor. This has a large positive association with "out" from times 11-20. |
pred2 |
Second simulated time-varying predictor. This has a moderate positive association with "out" from times 11-20. |
pred3 |
Third simulated time-varying predictor. This has a moderate negative association with "out" from times 1-10. |
pred4 |
Fourth simulated time-varying predictor. This has a strong negative association with "out" from times 1-10. |
pred5 |
Fifth simulated time-varying predictor. This has no significant association with "out". |