getting Error in chol.default(mat, pivot = TRUE) : 'a' must have dims > 0

Hi. I am running a GNM on the following data (sample) and getting an error. I ran a similar model a couple of months back without any issues. I am new to R and the community, so any help will be much appreciated.

data...

date Lost HIgroup1 PRgroup2 stratum_YMD
1-May-17 17 1 1 2017_5_20940
2-May-17 8 1 1 2017_5_20941
3-May-17 11 1 1 2017_5_20942
4-May-17 7 2 1 2017_5_20943
5-May-17 5 1 1 2017_5_20944
8-May-17 10 1 1 2017_5_20947
9-May-17 16 1 1 2017_5_20948
10-May-17 12 1 1 2017_5_20949
11-May-17 10 1 1 2017_5_20950
12-May-17 5 2 1 2017_5_20951
15-May-17 16 2 1 2017_5_20954
16-May-17 18 2 1 2017_5_20955
17-May-17 11 2 1 2017_5_20956
18-May-17 16 2 1 2017_5_20957
19-May-17 0 2 1 2017_5_20958
22-May-17 14 2 1 2017_5_20961
23-May-17 19 2 1 2017_5_20962
24-May-17 13 3 1 2017_5_20963
25-May-17 19 4 1 2017_5_20964
26-May-17 4 3 1 2017_5_20965
30-May-17 21 3 1 2017_5_20969
31-May-17 14 3 1 2017_5_20970
1-Jun-17 11 3 1 2017_6_20971
2-Jun-17 7 1 3 2017_6_20972
5-Jun-17 16 3 1 2017_6_20975
6-Jun-17 6 1 1 2017_6_20976
7-Jun-17 17 1 1 2017_6_20977
8-Jun-17 15 4 1 2017_6_20978
9-Jun-17 9 2 1 2017_6_20979
12-Jun-17 16 3 1 2017_6_20982
13-Jun-17 18 2 1 2017_6_20983
14-Jun-17 10 3 1 2017_6_20984
15-Jun-17 12 3 1 2017_6_20985
16-Jun-17 7 2 1 2017_6_20986
19-Jun-17 15 2 3 2017_6_20989
20-Jun-17 10 4 1 2017_6_20990
21-Jun-17 15 4 1 2017_6_20991
22-Jun-17 19 3 1 2017_6_20992
23-Jun-17 2 3 1 2017_6_20993
26-Jun-17 16 3 1 2017_6_20996
27-Jun-17 18 3 1 2017_6_20997
28-Jun-17 18 4 2 2017_6_20998
29-Jun-17 17 4 2 2017_6_20999
30-Jun-17 6 3 1 2017_6_21000
3-Jul-17 6 4 1 2017_7_21003
5-Jul-17 14 4 1 2017_7_21005
6-Jul-17 30 4 1 2017_7_21006
7-Jul-17 11 4 1 2017_7_21007
10-Jul-17 19 4 1 2017_7_21010
11-Jul-17 17 4 1 2017_7_21011
12-Jul-17 14 4 1 2017_7_21012
13-Jul-17 19 4 1 2017_7_21013
14-Jul-17 4 4 1 2017_7_21014
17-Jul-17 16 4 1 2017_7_21017
18-Jul-17 19 4 1 2017_7_21018
19-Jul-17 12 4 1 2017_7_21019
20-Jul-17 21 4 1 2017_7_21020
21-Jul-17 15 4 3 2017_7_21021
24-Jul-17 18 4 1 2017_7_21024
25-Jul-17 18 4 1 2017_7_21025
26-Jul-17 14 4 1 2017_7_21026
27-Jul-17 19 4 1 2017_7_21027
28-Jul-17 5 4 1 2017_7_21028
31-Jul-17 15 2 2 2017_7_21031
1-Aug-17 17 3 1 2017_8_21032
2-Aug-17 24 4 1 2017_8_21033
3-Aug-17 19 4 1 2017_8_21034
4-Aug-17 11 4 1 2017_8_21035
7-Aug-17 10 4 1 2017_8_21038
8-Aug-17 16 4 1 2017_8_21039
9-Aug-17 13 4 1 2017_8_21040
10-Aug-17 9 2 1 2017_8_21041
11-Aug-17 7 4 1 2017_8_21042
14-Aug-17 1 4 1 2017_8_21045
15-Aug-17 20 4 1 2017_8_21046
16-Aug-17 11 4 1 2017_8_21047
17-Aug-17 5 4 1 2017_8_21048
18-Aug-17 9 4 1 2017_8_21049
21-Aug-17 19 4 1 2017_8_21052
22-Aug-17 18 4 1 2017_8_21053
23-Aug-17 3 3 1 2017_8_21054
24-Aug-17 13 3 1 2017_8_21055
25-Aug-17 3 2 1 2017_8_21056
28-Aug-17 22 4 1 2017_8_21059
29-Aug-17 17 4 1 2017_8_21060
30-Aug-17 13 4 1 2017_8_21061
31-Aug-17 18 4 1 2017_8_21062
1-Sep-17 0 4 1 2017_9_21063
5-Sep-17 17 4 1 2017_9_21067
6-Sep-17 14 4 1 2017_9_21068
7-Sep-17 22 4 1 2017_9_21069
8-Sep-17 24 4 1 2017_9_21070
11-Sep-17 5 4 1 2017_9_21073
12-Sep-17 52 3 1 2017_9_21074
13-Sep-17 26 3 1 2017_9_21075
14-Sep-17 43 4 1 2017_9_21076
15-Sep-17 6 4 1 2017_9_21077
18-Sep-17 30 3 1 2017_9_21080
19-Sep-17 24 3 1 2017_9_21081
20-Sep-17 19 4 1 2017_9_21082
21-Sep-17 16 3 3 2017_9_21083
22-Sep-17 12 3 3 2017_9_21084
25-Sep-17 17 4 1 2017_9_21087
26-Sep-17 18 3 1 2017_9_21088
27-Sep-17 15 3 1 2017_9_21089
28-Sep-17 23 3 1 2017_9_21090
29-Sep-17 2 2 2 2017_9_21091
2-Oct-17 23 2 1 2017_10_21094
3-Oct-17 14 3 1 2017_10_21095
4-Oct-17 20 2 2 2017_10_21096
5-Oct-17 28 3 3 2017_10_21097
6-Oct-17 5 4 1 2017_10_21098
9-Oct-17 15 3 1 2017_10_21101
10-Oct-17 15 3 1 2017_10_21102
11-Oct-17 10 2 1 2017_10_21103
12-Oct-17 25 2 1 2017_10_21104
13-Oct-17 3 3 1 2017_10_21105
16-Oct-17 25 3 3 2017_10_21108
17-Oct-17 20 2 1 2017_10_21109
18-Oct-17 14 2 1 2017_10_21110
19-Oct-17 25 3 1 2017_10_21111
20-Oct-17 5 3 1 2017_10_21112
23-Oct-17 16 2 1 2017_10_21115
24-Oct-17 17 2 3 2017_10_21116
25-Oct-17 12 1 1 2017_10_21117
26-Oct-17 8 1 1 2017_10_21118
27-Oct-17 4 1 1 2017_10_21119
30-Oct-17 16 1 1 2017_10_21122
31-Oct-17 26 1 1 2017_10_21123

Model I ran...
test <- read_excel("test.xlsx")
library(gnm)

test$stratum_YMD <- as.factor(test$stratum_YMD)
test$HIgroup1 <- as.factor(test$HIgroup1)
test$PRgroup2 <- as.factor(test$PRgroup2)

one = gnm(Lost ~ HIgroup1 + PRgroup2 , data=test, family=poisson,eliminate=factor(stratum_YMD), exponentiate = TRUE)
summary(one)

Error....

test$stratum_YMD <- as.factor(test$stratum_YMD)
test$HIgroup1 <- as.factor(test$HIgroup1)
test$PRgroup2 <- as.factor(test$PRgroup2)
library(gnm)
one = gnm(Lost ~ HIgroup1 + PRgroup2 , data=test, family=poisson,eliminate=factor(stratum_YMD), exponentiate = TRUE)
summary(one)
Error in chol.default(mat, pivot = TRUE) : 'a' must have dims > 0

Not familiar with gnm, I suspect the problem is that stratum_YMD only has as many levels as values. When you set it as eliminate, you are including it it the model as an independent variable, so the fit fails (because each point has a different value).

You can see that by looking directly at the fit:

length(test$stratum_YMD) == length(levels(test$stratum_YMD))
#> [1] TRUE

one <- gnm::gnm(Lost ~ HIgroup1 + PRgroup2 , data=test, family=poisson,
                eliminate = stratum_YMD, exponentiate = TRUE)
one
#> 
#> Call:
#> gnm::gnm(formula = Lost ~ HIgroup1 + PRgroup2, eliminate = stratum_YMD, 
#>     family = poisson, data = test, exponentiate = TRUE)
#> 
#> Coefficients of interest:
#> HIgroup12  HIgroup13  HIgroup14  PRgroup22  PRgroup23  
#>        NA         NA         NA         NA         NA  
#> 
#> Deviance:            4.849983e-08 
#> Pearson chi-squared: 2.424991e-08 
#> Residual df:         0

one_no_stratum <- gnm::gnm(Lost ~ HIgroup1 + PRgroup2 , data=test, family=poisson,
                exponentiate = TRUE)
one_no_stratum
#> 
#> Call:
#> gnm::gnm(formula = Lost ~ HIgroup1 + PRgroup2, family = poisson, 
#>     data = test, exponentiate = TRUE)
#> 
#> Coefficients:
#> (Intercept)    HIgroup12    HIgroup13    HIgroup14    PRgroup22    PRgroup23  
#>     2.43792      0.12085      0.33983      0.26538      0.04811      0.14696  
#> 
#> Deviance:            526.6366 
#> Pearson chi-squared: 500.3253 
#> Residual df:         123

Created on 2020-12-07 by the reprex package (v0.3.0)

So, are you sure that stratum_YMD is an appropriate variable to include?

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.