bdlim1 {bdlim} | R Documentation |
Fit the BDLIM model with 1 pattern of modification
Description
Fit the BDLIM model with 1 pattern of modification
Usage
bdlim1(
y,
exposure,
covars,
group,
id = NULL,
w_free,
b_free,
df,
nits,
nburn = round(nits/2),
nthin = 1,
progress = TRUE
)
Arguments
y |
A vector of outcomes |
exposure |
A matrix of exposures with one row for each individual |
covars |
A matrix or data.frame of covariates This should not include the grouping factor (see group below). This may include factor variables. |
group |
A vector of group memberships. This should be a factor variable. |
id |
An optional vector of individual IDs if there are repeated measures or other groupings that a random intercept should be included for. This must be a factor variable. |
w_free |
Logical indicating if the weight functions are shared by all groups (FALSE) or group-specific (TRUE). |
b_free |
Logical indicating if the effect sizes are shared by all groups (FALSE) or group-specific (TRUE). |
df |
Degrees of freedom for the weight functions |
nits |
Number of MCMC iterations. |
nburn |
Number of MCMC iterations to be discarded as burn in. The default is half if the MCMC iterations. This is only used for WAIC in this function but is passed to summary and plot functions and used there. |
nthin |
Thinning factors for the MCMC. This is only used for WAIC in this function but is passed to summary and plot functions and used there. |
progress |
Logical indicating if a progress bar should be shown during MCMC iterations. Default is TRUE. |
Value
A list with posteriors of parameters
Examples
# run BDLIM with modification by ChildSex
fit_sex <- bdlim1(
y = sbd_bdlim$bwgaz,
exposure = sbd_bdlim[,paste0("pm25_",1:37)],
covars = sbd_bdlim[,c("MomPriorBMI","MomAge","race","Hispanic",
"EstMonthConcept","EstYearConcept")],
group = as.factor(sbd_bdlim$ChildSex),
w_free = TRUE,
b_free = TRUE,
df = 5,
nits = 5000
)
# show model fit results
fit_sex
#summarize results
sfit_sex <- summary(fit_sex)
sfit_sex
# graph the estimated distributed lag functions for each group
plot(sfit_sex)
# run BDLIM with no modification
# here a single group is put in for group
# the group must be a factor
# w_free and b_free must be FALSE because modification is not allowed with only one group
fit_onegroup <- bdlim1(
y = sbd_bdlim$bwgaz,
exposure = sbd_bdlim[,paste0("pm25_",1:37)],
covars = sbd_bdlim[,c("MomPriorBMI","MomAge","race","Hispanic",
"EstMonthConcept","EstYearConcept")],
group = as.factor(rep("A",nrow(sbd_bdlim))),
w_free = FALSE,
b_free = FALSE,
df = 5,
nits = 5000
)
# show model fit results
fit_onegroup
#summarize results
sfit_onegroup <- summary(fit_onegroup)
sfit_onegroup
# graph the estimated distributed lag functions for the one group
plot(sfit_onegroup)
# extract the weight function
getw(fit_onegroup)