1) if covars is a named matrix and exposure is a matrix (as suggested in the help file), then drop_na will fail because cbind will create a matrix, and drop_na doesn't have a matrix method. Also, when converted to a matrix, this will convert the factor group into a numeric variable, causing levels of group to be dropped, making names_groups <- levels(alldata$group) return NULL to names_group which would be incorrect.
REPREX:
# Convert covars to a matrix
named_Z <- as.matrix(sbd_bdlim[,c("MomPriorBMI")])
# Named matrix to skip the `if(is.null(colnames(covars)))` check
colnames(named_Z) <- "MomPriorBMI"
# X can be entered as a matrix as suggested in the docs
matrix_X <- as.matrix(sbd_bdlim[,paste0("pm25_",1:37)])
# Error because cbind(y,group,covars,exposure) returns a matrix and drop_na don't have a matrix method
fit_sex <- bdlim4(
y = sbd_bdlim$bwgaz,
exposure = matrix_X,
covars = named_Z,
group = as.factor(sbd_bdlim$ChildSex),
df = 5,
nits = 100,
parallel = FALSE
)
2) Hardcoded numbers of times the exposure measured to be 37 in line 78:
theta <- lm(rep(1/sqrt(37),37)~basis-1)$coef
REPREX:
# 37 is hardcoded
fit_sex <- bdlim4(
y = sbd_bdlim$bwgaz,
exposure = sbd_bdlim[,paste0("pm25_",1:36)],
covars = sbd_bdlim[,c("MomPriorBMI","MomAge","race","Hispanic",
"EstMonthConcept","EstYearConcept")],
group = as.factor(sbd_bdlim$ChildSex),
df = 5,
nits = 100,
parallel = FALSE
)
Fix 2 bugs in in R/bdlim1.R:
1) if covars is a named matrix and exposure is a matrix (as suggested in the help file), then
drop_na
will fail becausecbind
will create a matrix, anddrop_na
doesn't have a matrix method. Also, when converted to a matrix, this will convert the factorgroup
into a numeric variable, causing levels ofgroup
to be dropped, makingnames_groups <- levels(alldata$group)
return NULL tonames_group
which would be incorrect.REPREX:
2) Hardcoded numbers of times the exposure measured to be 37 in line 78: theta <- lm(rep(1/sqrt(37),37)~basis-1)$coef
REPREX: