I recently tried to conduct model averaging on a glm fitted with gamlss
using MuMIn
's dredge
function and am getting the same error as these two other users here and here. Here is a reproducible example and the error:
library(gamlss)
library(MuMIn)
#data
structure(list(offset_var = c(1.28599085563929, 0.56011798945881,
0.910539373132146, 1.40150012655384, 1.99332290786881, 0.431352036569322,
1.9664387276399, 0.39501204122542, 0.837952086514098, 1.49309174747163,
0.185176379335315, 0.340780160418832, 0.23261768703236, 1.9358463846208,
0.683228994093252, 0.766384544663353, 2.36951602293399, 0.570222733062088,
2.035225147398, 2.66190465894079, 2.59441609615926, 2.45851192989865,
9.10131475225225, 1.79085721952421, 1.14341199635633, 1.86464965904907,
0.969684569635742, 1.48586083003075, 0.398395739771472, 1.57819408350658,
0.348242838034098, 1.01779798183851, 1.56020949397414, 1.14211413937976,
1.15472189286642, 2.17372502761175, 2.17372502761175, 1.15472189286642,
0.91480376034087, 0.52428786649856, 0.663761139444733, 1.85426680323653,
0.799109081286816, 1.2592920835499, 1.32010595330908, 1.9473416892704,
1.74079702185659, 1.92731761020335), response_var = c(31, 154,
40, 71, 3, 43, 66, 180, 62, 27, 84, 81, 66, 14, 40, 35, 48, 155,
23, 37, 33, 88, 38, 8, 73, 29, 11, 12, 74, 70, 298, 40, 24, 35,
0, 27, 0, 116, 83, 60, 77, 68, 56, 8, 64, 234, 57, 71), pred1 = c(0.593253968253968,
0.212619047619048, 0.208888888888889, 0.824603174603175, 0.791031746031746,
0.096984126984127, 0.589523809523809, 0.096984126984127, 0.783571428571429,
0.156666666666667, 0, 0.361904761904762, 0.164126984126984, 0.723809523809524,
0.123095238095238, 0.671587301587302, 0.708888888888889, 0.186507936507937,
0.77984126984127, 0.0820634920634921, 0.220079365079365, 1, 0.27984126984127,
0.835793650793651, 0.526031746031746, 0.0298412698412698, 0.641746031746032,
0.0783333333333333, 0.156666666666667, 0.791031746031746, 0.167857142857143,
0.641746031746032, 0.817142857142857, 0.126825396825397, 0.160396825396825,
0.776031746031746, 0.776031746031746, 0.160396825396825, 0.130555555555556,
0.600714285714286, 0.123095238095238, 0.70515873015873, 0.164126984126984,
0.492460317460317, 0.0932539682539683, 0.596984126984127, 0.134285714285714,
0.899206349206349), pred3 = c(0.779445727482678, 0.779445727482678,
0.981524249422633, 0.981524249422633, 0.431293302540416, 0.431293302540416,
0.85796766743649, 0.85796766743649, 0.974018475750578, 0.974018475750578,
0.215357967667437, 0.215357967667437, 0.767898383371826, 0.767898383371826,
0.929561200923788, 0.929561200923788, 0.319861431870669, 0.319861431870669,
0.930138568129331, 0.930138568129331, 1, 1, 0.753464203233256,
0.753464203233256, 0.937644341801385, 0.937644341801385, 0.438799076212472,
0.438799076212472, 0.960161662817552, 0.960161662817552, 0.852193995381064,
0.852193995381064, 0.803117782909932, 0.803117782909932, 0.571593533487299,
0.571593533487299, 0.571593533487299, 0.571593533487299, 0, 0,
0.801385681293304, 0.801385681293304, 0.656466512702079, 0.656466512702079,
0.852771362586606, 0.852771362586606, 0.203810623556583, 0.203810623556583
), pred6 = c(0.688053824835413, 0.540952466204905, 0.628399305213738,
0.6881894451542, 0.780506864063453, 0.596192469087064, 0.664351792193705,
0.601630037911551, 0.725643181043039, 0.617634868802872, 0.811784880984014,
0.804339479465123, 0.576349468957153, 0.847678636187369, 0.625702671539389,
0.719554647550091, 0.363763777714112, 0.446477292582477, 0.474674252997289,
0.480035185899025, 0.4937661725622, 0, 0.513379111687292, 0.903418101749096,
0.695930304479286, 0.617335579129072, 0.759590008590574, 0.654198263624173,
0.638351745840282, 0.758157124611394, 0.616963963666818, 0.749652691590418,
0.626922408721354, 0.587580912470206, 0.430636110291636, 0.349235608213707,
0.349235608213707, 0.430636110291636, 0.723455668440276, 1, 0.615287637567703,
0.696660949537828, 0.570881476208878, 0.51486263616898, 0.599650096633513,
0.661291018750272, 0.44995045321675, 0.317335721700076), pred2 = c(0.0640028225107189,
0.0640028225107189, 1, 1, 0.0467149443570715, 0.0467149443570715,
0.955928169494161, 0.955928169494161, 0.991149754525286, 0.991149754525286,
0.636541945977623, 0.636541945977623, 0.0695282460368243, 0.0695282460368243,
0.945044759518499, 0.945044759518499, 0.666620820800469, 0.666620820800469,
0.865751343981534, 0.865751343981534, 0.158030700783964, 0.158030700783964,
0, 0, 0.941696017987526, 0.941696017987526, 0.194526003575978,
0.194526003575978, 0.974286448958601, 0.974286448958601, 0.182153599598151,
0.182153599598151, 0.834117696305023, 0.834117696305023, 0.729828317197582,
0.729828317197582, 0.729828317197582, 0.729828317197582, 0.477488683047594,
0.477488683047594, 0.914726688872012, 0.914726688872012, 0.0551346373492319,
0.0551346373492319, 0.950905057197701, 0.950905057197701, 0.653584648412039,
0.653584648412039), pred4 = c(0.521197167238095, 0.521197167238095,
0.675165075565519, 0.675165075565519, 0.754750741994489, 0.754750741994489,
0.656214157700682, 0.656214157700682, 0.779025156922262, 0.779025156922262,
0.466656174770789, 0.466656174770789, 1, 1, 0.19412522736884,
0.19412522736884, 0, 0, 0.914127451104004, 0.914127451104004,
0.450341983837599, 0.450341983837599, 0.200288723846985, 0.200288723846985,
0.51864603534987, 0.51864603534987, 0.632983879774839, 0.632983879774839,
0.219950187016786, 0.219950187016786, 0.378371968866928, 0.378371968866928,
0.332552996854781, 0.332552996854781, 0.543573394076179, 0.543573394076179,
0.543573394076179, 0.543573394076179, 0.110505257947263, 0.110505257947263,
0.80446053190608, 0.80446053190608, 0.942739062050578, 0.942739062050578,
0.769130578963835, 0.769130578963835, 0.910376608809312, 0.910376608809312
), pred5 = c(1, 1, 0.277346201087263, 0.277346201087263, 0.977777461589862,
0.977777461589862, 0.690563309054654, 0.690563309054654, 0.439008770827643,
0.439008770827643, 0.819995545023047, 0.819995545023047, 0.579039846892373,
0.579039846892373, 0.365538938318013, 0.365538938318013, 0.0971685384896833,
0.0971685384896833, 0.599718772091419, 0.599718772091419, 0.871837464542416,
0.871837464542416, 0.0550210151699806, 0.0550210151699806, 0.740706048133834,
0.740706048133834, 0.0826796777514591, 0.0826796777514591, 0.52020534667614,
0.52020534667614, 0, 0, 0.660904950317592, 0.660904950317592,
0.790027991312289, 0.790027991312289, 0.790027991312289, 0.790027991312289,
0.206354045553633, 0.206354045553633, 0.600235537123976, 0.600235537123976,
0.829243121962118, 0.829243121962118, 0.595320097430252, 0.595320097430252,
0.17138558268267, 0.17138558268267)), row.names = c(NA, -48L), class = "data.frame")
#glm with gamlss
model <-gamlss(response_var~pred1*pred2 + pred1*pred3 + pred1*pred4 + pred1*pred5 + pred6 + offset(log(offset_var)), data=df, family=NBI)
#dredge
model_set<-dredge(model)
Error in dimnames(deps) <- list(rval, rval) : length of 'dimnames' [1] not equal to array extent
It seems that the error has something to do with the dependency matrix ("deps"), which according to the help file for dredge
is
a “dependency matrix” as returned by getAllTerms, attribute "deps". Can be used to fine-tune marginality exceptions.
The latest package documentation still includes gamlss
as a supported model class, but given that the two questions above were asked last year (an both unanswered) I'm guessing that this problem has existed for a while. I am posting this here because I am unable to find the MuMIn
github page to post as an issue. If anyone knows any fix for this or has any updates it would be much appreciated!
Edit: sessionInfo() after updating to MuMIn
1.46.3:
R version 4.2.0 (2022-04-22 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19043)
Matrix products: default
Random number generation:
RNG: Mersenne-Twister
Normal: Inversion
Sample: Rounding
locale:
[1] LC_COLLATE=English_Canada.utf8 LC_CTYPE=English_Canada.utf8 LC_MONETARY=English_Canada.utf8 LC_NUMERIC=C LC_TIME=English_Canada.utf8
attached base packages:
[1] parallel splines stats graphics grDevices utils datasets methods base
other attached packages:
[1] gamlss_5.4-3 nlme_3.1-157 gamlss.dist_6.0-3 MASS_7.3-56 gamlss.data_6.0-2 MuMIn_1.46.3
loaded via a namespace (and not attached):
[1] magrittr_2.0.3 tidyselect_1.1.2 lattice_0.20-45 R6_2.5.1 rlang_1.0.2 fansi_1.0.3 dplyr_1.0.9 tools_4.2.0 grid_4.2.0 utf8_1.2.2
[11] cli_3.3.0 DBI_1.1.2 ellipsis_0.3.2 survival_3.3-1 assertthat_0.2.1 tibble_3.1.7 lifecycle_1.0.1 crayon_1.5.1 Matrix_1.4-1 purrr_0.3.4
[21] vctrs_0.4.1 glue_1.6.2 compiler_4.2.0 pillar_1.7.0 generics_0.1.2 stats4_4.2.0 pkgconfig_2.0.3 ```
It is a bug related to the handling of intercept only models and offset
in formulas. Fixed in MuMIn version 1.46.5 (for now on R-Forge).