I feel like I'm missing something really obvious here. I'm using the R package DLNM to fit a model. It's happening inside a function (not shown) so that I can feed in different datasets and change the model options. The function returns a list (shown below) with the crossbasis (cb.t
) and the fitted model (mod
). The DLNM function crosspred()
works like a charm when I feed in the individual objects:
# load packages
library(dlnm)
library(splines)
# fit model
varknots.t <- quantile(dat$tmin, probs = c(0.1, 0.5, 0.9))
cb.t <- crossbasis(dat$tmin,
lag = 4,
argvar = list(fun = "bs", knots = varknots.t, degree = 3),
arglag = list(fun = "bs", df = 4, degree = 3))
mod <- glm(n_pre ~ cb.t + bs(doy, degree = 3, knots = 196) + factor(dow) + race_mom,
offset = log(n_tot_expected),
family = quasipoisson(),
data = dat)
# this works
crosspred(cb.t,
mod,
cen = 67,
bylag = 0.1)
But crosspred()
throws an error when I try to access the exact same objects in a list:
# but this doesn't work
crosspred(list(cb.t, mod)[[1]],
list(cb.t, mod)[[2]],
cen = 67,
bylag = 0.1)
"Error in crosspred(list(cb.t, mod)[[1]], list(cb.t, mod)[[2]], cen = 67, :
coef/vcov not consistent with basis matrix. See help(crosspred)"
Why isn't crosspred()
working when I try to access the arguments from a list? Can anyone spot my mistake? Seems like something really simple I'm just missing.
A reproducible example is below. In case the context helps, I'm attempting to do a very similar analysis as in Darrow et al (2024), of estimating the exposure-response function for the impact of temperature on preterm birth rates:
A reproducible example is below:
dat <- structure(list(date = structure(c(5631, 5632, 5635, 5636, 5638,
5641, 5642, 5643, 5646, 5650, 5652, 5654, 5656, 5660, 5661, 5662,
5665, 5669, 5670, 5671, 5672, 5673, 5675, 5677, 5678, 5681, 5682,
5684, 5685, 5686, 5688, 5690, 5691, 5692, 5694, 5695, 5696, 5697,
5700, 5701, 5702, 5703, 5706, 5707, 5709, 5711, 5712, 5716, 5719,
5720, 5721, 5694, 5704, 5630, 5631, 5632, 5633, 5634, 5635, 5636,
5637, 5638, 5639, 5640, 5641, 5642, 5643, 5644, 5645, 5646, 5647,
5648, 5649, 5650, 5651, 5652, 5653, 5654, 5655, 5656, 5657, 5658,
5659, 5661, 5662, 5663, 5664, 5665, 5667, 5668, 5669, 5670, 5671,
5672, 5673, 5674, 5675, 5676, 5677, 5678, 5679, 5680, 5681, 5682,
5683, 5684, 5685, 5686, 5687, 5688, 5689, 5690, 5691, 5692, 5693,
5694, 5695, 5696, 5697, 5698, 5699, 5700, 5701, 5702, 5703, 5704,
5705, 5706, 5707, 5708, 5709, 5710, 5711, 5712, 5713, 5714, 5715,
5716, 5717, 5718, 5720, 5721), class = "Date"),
tmin = c(73, 71.1, 73, 73, 69.1, 69.1, 55.9, 53.1, 70, 60.1, 70, 71.1, 70,
66, 64, 62.1, 68, 70, 68, 68, 70, 73, 72, 72, 70, 72, 70, 73,
73, 71.1, 73, 73, 73, 71.1, 64, 64, 71.1, 73, 71.1, 72, 72, 71.1,
72, 73, 66, 70, 66, 66, 71.1, 70, 64.9, 64, 70, 71.1, 73, 71.1,
70, 71.1, 73, 73, 66.9, 69.1, 73.9, 57, 69.1, 55.9, 53.1, 61,
68, 70, 68, 66.9, 57.9, 60.1, 63, 70, 70, 71.1, 69.1, 70, 72,
69.1, 66.9, 64, 62.1, 66.9, 66, 68, 68, 68, 70, 68, 68, 70, 73,
69.1, 72, 69.1, 72, 70, 69.1, 71.1, 72, 70, 72, 73, 73, 71.1,
71.1, 73, 73.9, 73, 73, 71.1, 70, 64, 64, 71.1, 73, 72, 70, 71.1,
72, 72, 71.1, 70, 71.1, 72, 73, 70, 66, 71.1, 70, 66, 69.1, 72,
68, 66, 69.1, 68, 70, 64.9), doy = c(153, 154, 157, 158, 160,
163, 164, 165, 168, 172, 174, 176, 178, 182, 183, 184, 187, 191,
192, 193, 194, 195, 197, 199, 200, 203, 204, 206, 207, 208, 210,
212, 213, 214, 216, 217, 218, 219, 222, 223, 224, 225, 228, 229,
231, 233, 234, 238, 241, 242, 243, 216, 226, 152, 153, 154, 155,
156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168,
169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181,
183, 184, 185, 186, 187, 189, 190, 191, 192, 193, 194, 195, 196,
197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209,
210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222,
223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235,
236, 237, 238, 239, 240, 242, 243),
dow = structure(c(4L, 2L, 5L, 1L, 4L, 7L, 5L, 1L, 2L, 1L, 4L, 6L,
5L, 2L, 6L, 7L, 3L, 7L, 5L, 1L, 3L, 4L, 6L, 5L, 1L, 2L, 6L, 5L,
1L, 3L, 2L, 7L, 5L, 1L, 4L, 2L, 6L, 7L, 3L, 4L, 2L, 6L, 1L, 3L,
2L, 7L, 5L, 2L, 5L, 1L, 3L, 4L, 7L, 3L, 4L, 2L, 6L, 7L, 5L, 1L,
3L, 4L, 2L, 6L, 7L, 5L, 1L, 3L, 4L, 2L, 6L, 7L, 5L, 1L, 3L, 4L,
2L, 6L, 7L, 5L, 1L, 3L, 4L, 6L, 7L, 5L, 1L, 3L, 2L, 6L, 7L, 5L,
1L, 3L, 4L, 2L, 6L, 7L, 5L, 1L, 3L, 4L, 2L, 6L, 7L, 5L, 1L, 3L,
4L, 2L, 6L, 7L, 5L, 1L, 3L, 4L, 2L, 6L, 7L, 5L, 1L, 3L, 4L, 2L,
6L, 7L, 5L, 1L, 3L, 4L, 2L, 6L, 7L, 5L, 1L, 3L, 4L, 2L, 6L, 7L, 1L, 3L),
levels = c("Friday", "Monday", "Saturday", "Sunday", "Thursday", "Tuesday", "Wednesday"
), class = "factor"),
race_mom = c("Black", "Black", "Black",
"Black", "Black", "Black", "Black", "Black", "Black", "Black",
"Black", "Black", "Black", "Black", "Black", "Black", "Black",
"Black", "Black", "Black", "Black", "Black", "Black", "Black",
"Black", "Black", "Black", "Black", "Black", "Black", "Black",
"Black", "Black", "Black", "Black", "Black", "Black", "Black",
"Black", "Black", "Black", "Black", "Black", "Black", "Black",
"Black", "Black", "Black", "Black", "Black", "Black", "Other",
"Other", "White", "White", "White", "White", "White", "White",
"White", "White", "White", "White", "White", "White", "White",
"White", "White", "White", "White", "White", "White", "White",
"White", "White", "White", "White", "White", "White", "White",
"White", "White", "White", "White", "White", "White", "White",
"White", "White", "White", "White", "White", "White", "White",
"White", "White", "White", "White", "White", "White", "White",
"White", "White", "White", "White", "White", "White", "White",
"White", "White", "White", "White", "White", "White", "White",
"White", "White", "White", "White", "White", "White", "White",
"White", "White", "White", "White", "White", "White", "White",
"White", "White", "White", "White", "White", "White", "White",
"White", "White", "White", "White", "White", "White"),
n_tot_expected = c(0.699508051770179, 0.616551196461173, 0.765417070089907, 0.74640258511336, 0.744571450928639, 0.875741426370749, 0.782758912109837, 0.759532588172667, 0.772890765171021, 0.968630725657242, 0.947829950362199, 0.986072317058252, 0.881153047220655, 1.07740915333439, 1.18333811855132, 1.06014630511613, 1.25285416150582, 1.38462049811691, 1.40213891993446, 1.41876487953219, 1.2953328471704, 1.2977284005842, 1.26328923255157, 1.12052360106438, 1.1340688716649,
1.27879471121969, 1.20958102958826, 1.30253261242657, 1.34981986548187, 1.3216369121752, 1.38038091511738, 1.3304552216927, 1.30092540695055, 1.15295595548287, 1.15565996384269, 1.11152521911895, 1.14132900175733, 1.05835356459398, 0.85303812140892, 0.883128899337899, 0.935769717938481, 0.947097190638695, 1.02186529164577, 1.0545819564197, 1.1801123030532, 1.26050452646698, 1.21950351002005, 1.45856870472636, 1.59950929242577, 1.69232185821741, 1.62015446701294, 0.131740900924605, 0.0974659670542284, 3.70365604942418, 3.58657283618486, 3.50719646537878, 3.30632176913375, 3.48493228272366, 3.09077663491357, 3.29272097034219, 3.22445301021395, 3.15367698689957, 3.06999177125248, 3.11086146213385, 3.0934619442639, 3.02872228203929, 3.14368395326626, 3.16396033862508, 2.9089892701092,
2.92044515142426, 2.725965174562, 2.82928157661259, 2.87905199360893, 2.93066860762022, 3.09857654442203, 3.25500847955825, 3.18597832092678, 3.08908361181888, 2.99472455671304, 2.84026126576718, 3.02152868870933, 3.18569526507437, 3.29687990256811, 3.75716990327002, 3.50792705664034, 3.5460359692208, 3.97405426164111, 3.85733100575202, 4.1546014678629,
4.1564963074783, 4.28151268849292, 4.53427318842027, 4.69251003976591, 4.44170733218653, 4.58236219046372, 4.83173649407459, 4.64739558010683, 4.30501505854004, 4.45338674133272, 4.64612012913764, 4.35397996087347, 4.5062674850727, 4.82089186182934, 4.69444183020684, 4.58619660009243, 4.61919960835621, 4.62809081990766, 4.38297444056452, 4.43797734873728,
4.65894168222206, 4.41793634264914, 4.20319124892724, 4.12238758059117, 4.30994056802256, 4.15510794038985, 4.22039506640016, 4.21097267149318, 4.25220320530536, 4.1354393207188, 4.26548253615952, 4.26115302953313, 4.09700967554119, 4.01761628744604, 4.05803916562496, 3.95488305050557, 4.08433111537984, 4.2164975818537, 4.36116211509861, 4.44399363459998,
4.26440647012014, 3.87938739098403, 3.73015132903498, 3.96551204210303, 4.09105766613588, 4.12129574495662, 4.10931468162365, 4.20330937427431, 4.1943501003521, 4.22347929041182, 4.40833793309973, 4.51322849478503, 4.47761812866045),
n_pre = c(1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0,
0, 2, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0,
0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0,
1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1,
0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0,
0, 1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0,
1, 0, 1, 0, 0)),
row.names = c(NA, -142L), class = c("tbl_df", "tbl", "data.frame"))
I feel like I'm missing something really obvious here. I'm using the R package DLNM to fit a model. It's happening inside a function (not shown) so that I can feed in different datasets and change the model options. The function returns a list (shown below) with the crossbasis (cb.t
) and the fitted model (mod
). The DLNM function crosspred()
works like a charm when I feed in the individual objects:
# load packages
library(dlnm)
library(splines)
# fit model
varknots.t <- quantile(dat$tmin, probs = c(0.1, 0.5, 0.9))
cb.t <- crossbasis(dat$tmin,
lag = 4,
argvar = list(fun = "bs", knots = varknots.t, degree = 3),
arglag = list(fun = "bs", df = 4, degree = 3))
mod <- glm(n_pre ~ cb.t + bs(doy, degree = 3, knots = 196) + factor(dow) + race_mom,
offset = log(n_tot_expected),
family = quasipoisson(),
data = dat)
# this works
crosspred(cb.t,
mod,
cen = 67,
bylag = 0.1)
But crosspred()
throws an error when I try to access the exact same objects in a list:
# but this doesn't work
crosspred(list(cb.t, mod)[[1]],
list(cb.t, mod)[[2]],
cen = 67,
bylag = 0.1)
"Error in crosspred(list(cb.t, mod)[[1]], list(cb.t, mod)[[2]], cen = 67, :
coef/vcov not consistent with basis matrix. See help(crosspred)"
Why isn't crosspred()
working when I try to access the arguments from a list? Can anyone spot my mistake? Seems like something really simple I'm just missing.
A reproducible example is below. In case the context helps, I'm attempting to do a very similar analysis as in Darrow et al (2024), of estimating the exposure-response function for the impact of temperature on preterm birth rates: https://jamanetwork/journals/jamanetworkopen/fullarticle/2819253
A reproducible example is below:
dat <- structure(list(date = structure(c(5631, 5632, 5635, 5636, 5638,
5641, 5642, 5643, 5646, 5650, 5652, 5654, 5656, 5660, 5661, 5662,
5665, 5669, 5670, 5671, 5672, 5673, 5675, 5677, 5678, 5681, 5682,
5684, 5685, 5686, 5688, 5690, 5691, 5692, 5694, 5695, 5696, 5697,
5700, 5701, 5702, 5703, 5706, 5707, 5709, 5711, 5712, 5716, 5719,
5720, 5721, 5694, 5704, 5630, 5631, 5632, 5633, 5634, 5635, 5636,
5637, 5638, 5639, 5640, 5641, 5642, 5643, 5644, 5645, 5646, 5647,
5648, 5649, 5650, 5651, 5652, 5653, 5654, 5655, 5656, 5657, 5658,
5659, 5661, 5662, 5663, 5664, 5665, 5667, 5668, 5669, 5670, 5671,
5672, 5673, 5674, 5675, 5676, 5677, 5678, 5679, 5680, 5681, 5682,
5683, 5684, 5685, 5686, 5687, 5688, 5689, 5690, 5691, 5692, 5693,
5694, 5695, 5696, 5697, 5698, 5699, 5700, 5701, 5702, 5703, 5704,
5705, 5706, 5707, 5708, 5709, 5710, 5711, 5712, 5713, 5714, 5715,
5716, 5717, 5718, 5720, 5721), class = "Date"),
tmin = c(73, 71.1, 73, 73, 69.1, 69.1, 55.9, 53.1, 70, 60.1, 70, 71.1, 70,
66, 64, 62.1, 68, 70, 68, 68, 70, 73, 72, 72, 70, 72, 70, 73,
73, 71.1, 73, 73, 73, 71.1, 64, 64, 71.1, 73, 71.1, 72, 72, 71.1,
72, 73, 66, 70, 66, 66, 71.1, 70, 64.9, 64, 70, 71.1, 73, 71.1,
70, 71.1, 73, 73, 66.9, 69.1, 73.9, 57, 69.1, 55.9, 53.1, 61,
68, 70, 68, 66.9, 57.9, 60.1, 63, 70, 70, 71.1, 69.1, 70, 72,
69.1, 66.9, 64, 62.1, 66.9, 66, 68, 68, 68, 70, 68, 68, 70, 73,
69.1, 72, 69.1, 72, 70, 69.1, 71.1, 72, 70, 72, 73, 73, 71.1,
71.1, 73, 73.9, 73, 73, 71.1, 70, 64, 64, 71.1, 73, 72, 70, 71.1,
72, 72, 71.1, 70, 71.1, 72, 73, 70, 66, 71.1, 70, 66, 69.1, 72,
68, 66, 69.1, 68, 70, 64.9), doy = c(153, 154, 157, 158, 160,
163, 164, 165, 168, 172, 174, 176, 178, 182, 183, 184, 187, 191,
192, 193, 194, 195, 197, 199, 200, 203, 204, 206, 207, 208, 210,
212, 213, 214, 216, 217, 218, 219, 222, 223, 224, 225, 228, 229,
231, 233, 234, 238, 241, 242, 243, 216, 226, 152, 153, 154, 155,
156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168,
169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181,
183, 184, 185, 186, 187, 189, 190, 191, 192, 193, 194, 195, 196,
197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209,
210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222,
223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235,
236, 237, 238, 239, 240, 242, 243),
dow = structure(c(4L, 2L, 5L, 1L, 4L, 7L, 5L, 1L, 2L, 1L, 4L, 6L,
5L, 2L, 6L, 7L, 3L, 7L, 5L, 1L, 3L, 4L, 6L, 5L, 1L, 2L, 6L, 5L,
1L, 3L, 2L, 7L, 5L, 1L, 4L, 2L, 6L, 7L, 3L, 4L, 2L, 6L, 1L, 3L,
2L, 7L, 5L, 2L, 5L, 1L, 3L, 4L, 7L, 3L, 4L, 2L, 6L, 7L, 5L, 1L,
3L, 4L, 2L, 6L, 7L, 5L, 1L, 3L, 4L, 2L, 6L, 7L, 5L, 1L, 3L, 4L,
2L, 6L, 7L, 5L, 1L, 3L, 4L, 6L, 7L, 5L, 1L, 3L, 2L, 6L, 7L, 5L,
1L, 3L, 4L, 2L, 6L, 7L, 5L, 1L, 3L, 4L, 2L, 6L, 7L, 5L, 1L, 3L,
4L, 2L, 6L, 7L, 5L, 1L, 3L, 4L, 2L, 6L, 7L, 5L, 1L, 3L, 4L, 2L,
6L, 7L, 5L, 1L, 3L, 4L, 2L, 6L, 7L, 5L, 1L, 3L, 4L, 2L, 6L, 7L, 1L, 3L),
levels = c("Friday", "Monday", "Saturday", "Sunday", "Thursday", "Tuesday", "Wednesday"
), class = "factor"),
race_mom = c("Black", "Black", "Black",
"Black", "Black", "Black", "Black", "Black", "Black", "Black",
"Black", "Black", "Black", "Black", "Black", "Black", "Black",
"Black", "Black", "Black", "Black", "Black", "Black", "Black",
"Black", "Black", "Black", "Black", "Black", "Black", "Black",
"Black", "Black", "Black", "Black", "Black", "Black", "Black",
"Black", "Black", "Black", "Black", "Black", "Black", "Black",
"Black", "Black", "Black", "Black", "Black", "Black", "Other",
"Other", "White", "White", "White", "White", "White", "White",
"White", "White", "White", "White", "White", "White", "White",
"White", "White", "White", "White", "White", "White", "White",
"White", "White", "White", "White", "White", "White", "White",
"White", "White", "White", "White", "White", "White", "White",
"White", "White", "White", "White", "White", "White", "White",
"White", "White", "White", "White", "White", "White", "White",
"White", "White", "White", "White", "White", "White", "White",
"White", "White", "White", "White", "White", "White", "White",
"White", "White", "White", "White", "White", "White", "White",
"White", "White", "White", "White", "White", "White", "White",
"White", "White", "White", "White", "White", "White", "White",
"White", "White", "White", "White", "White", "White"),
n_tot_expected = c(0.699508051770179, 0.616551196461173, 0.765417070089907, 0.74640258511336, 0.744571450928639, 0.875741426370749, 0.782758912109837, 0.759532588172667, 0.772890765171021, 0.968630725657242, 0.947829950362199, 0.986072317058252, 0.881153047220655, 1.07740915333439, 1.18333811855132, 1.06014630511613, 1.25285416150582, 1.38462049811691, 1.40213891993446, 1.41876487953219, 1.2953328471704, 1.2977284005842, 1.26328923255157, 1.12052360106438, 1.1340688716649,
1.27879471121969, 1.20958102958826, 1.30253261242657, 1.34981986548187, 1.3216369121752, 1.38038091511738, 1.3304552216927, 1.30092540695055, 1.15295595548287, 1.15565996384269, 1.11152521911895, 1.14132900175733, 1.05835356459398, 0.85303812140892, 0.883128899337899, 0.935769717938481, 0.947097190638695, 1.02186529164577, 1.0545819564197, 1.1801123030532, 1.26050452646698, 1.21950351002005, 1.45856870472636, 1.59950929242577, 1.69232185821741, 1.62015446701294, 0.131740900924605, 0.0974659670542284, 3.70365604942418, 3.58657283618486, 3.50719646537878, 3.30632176913375, 3.48493228272366, 3.09077663491357, 3.29272097034219, 3.22445301021395, 3.15367698689957, 3.06999177125248, 3.11086146213385, 3.0934619442639, 3.02872228203929, 3.14368395326626, 3.16396033862508, 2.9089892701092,
2.92044515142426, 2.725965174562, 2.82928157661259, 2.87905199360893, 2.93066860762022, 3.09857654442203, 3.25500847955825, 3.18597832092678, 3.08908361181888, 2.99472455671304, 2.84026126576718, 3.02152868870933, 3.18569526507437, 3.29687990256811, 3.75716990327002, 3.50792705664034, 3.5460359692208, 3.97405426164111, 3.85733100575202, 4.1546014678629,
4.1564963074783, 4.28151268849292, 4.53427318842027, 4.69251003976591, 4.44170733218653, 4.58236219046372, 4.83173649407459, 4.64739558010683, 4.30501505854004, 4.45338674133272, 4.64612012913764, 4.35397996087347, 4.5062674850727, 4.82089186182934, 4.69444183020684, 4.58619660009243, 4.61919960835621, 4.62809081990766, 4.38297444056452, 4.43797734873728,
4.65894168222206, 4.41793634264914, 4.20319124892724, 4.12238758059117, 4.30994056802256, 4.15510794038985, 4.22039506640016, 4.21097267149318, 4.25220320530536, 4.1354393207188, 4.26548253615952, 4.26115302953313, 4.09700967554119, 4.01761628744604, 4.05803916562496, 3.95488305050557, 4.08433111537984, 4.2164975818537, 4.36116211509861, 4.44399363459998,
4.26440647012014, 3.87938739098403, 3.73015132903498, 3.96551204210303, 4.09105766613588, 4.12129574495662, 4.10931468162365, 4.20330937427431, 4.1943501003521, 4.22347929041182, 4.40833793309973, 4.51322849478503, 4.47761812866045),
n_pre = c(1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0,
0, 2, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0,
0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0,
1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1,
0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0,
0, 1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0,
1, 0, 1, 0, 0)),
row.names = c(NA, -142L), class = c("tbl_df", "tbl", "data.frame"))
Share
Improve this question
asked Mar 21 at 4:06
jdcodejdcode
1471 silver badge9 bronze badges
2
|
1 Answer
Reset to default 2The model (mod
) must include the basis name (cb.t
), otherwise you will get an error.
mod <- glm(n_pre ~ cb.t + ...
The first term above must exactly match the basis name you provide in the call to the function. Your second example doesn't work because the function code is using regex to look for:
list(cb.t, mod)[[1]]
in the names of the model coefficients at line 57:
else grep(cond, names(coef))
And this name "cond", which is assigned on line 43, doesn't exist. Line 26:
name <- deparse(substitute(basis))
is also relevant as it grabs the actual name of the basis object in the function call.
else grep(cond, names(coef))
. – Edward Commented Mar 21 at 4:24