Я пытаюсь подобрать модель со случайным марковским полем, гладким в mgcv
. У меня возникли некоторые проблемы с его запуском, и, в частности, я получаю сообщение
Ошибка в initial.sp (w * x, S, off): S [[1]] матрица не + ve определенное.
После прочтения всего, что я смог найти в MRF, похоже, что в 2012 году в Simon Wood была обнаружена ошибка, связанная с различиями между Windows и Linux, с Машина Линуса останавливается из-за этой ошибки, пока windows не было. Я не смог найти что-то еще по этому поводу. Будем благодарны за любые предложения.
Ниже приведен воспроизводимый код.
library(mgcv)
#create data
Country <- as.factor(c("Australia","Australia","Australia","Australia","Australia","Australia","Bangladesh","Bangladesh","Bangladesh",
"Bangladesh","Bangladesh","Bangladesh","Cambodia","Cambodia","Cambodia","Cambodia","Cambodia","Cambodia",
"China","China","China","China","China","China","East Timor","East Timor","East Timor",
"East Timor","East Timor","East Timor","HighSeas1","HighSeas1","HighSeas1","HighSeas1","HighSeas1","HighSeas1",
"HighSeas2","HighSeas2","HighSeas2","HighSeas2","HighSeas2","HighSeas2","China","China","China","China","China","China",
"India","India","India","India","India","India","Indonesia","Indonesia","Indonesia","Indonesia","Indonesia","Indonesia",
"Malaysia","Malaysia","Malaysia","Malaysia","Malaysia","Malaysia","Myanmar","Myanmar","Myanmar","Myanmar","Myanmar",
"Myanmar","Philippines","Philippines","Philippines","Philippines","Philippines","Philippines","South Korea","South Korea",
"South Korea","South Korea","South Korea","South Korea","China","China","China","China","China","China",
"Sri Lanka","Sri Lanka","Sri Lanka","Sri Lanka","Sri Lanka","Sri Lanka","Taiwan","Taiwan","Taiwan","Taiwan",
"Taiwan","Taiwan","Thailand","Thailand","Thailand","Thailand","Thailand","Thailand","Vietnam","Vietnam","Vietnam","Vietnam",
"Vietnam","Vietnam"))
Count <- c(0,0,3,5,1,5,0,0,0,0,0,1,0,0,0,0,0,3,0,0,2,1,0,6,0,0,0,1,0,0,0,1,0,0,0,0
,0,0,20,0,1,0,0,0,0,0,0,2,0,0,6,3,3,10,1,1,18,11,8,11,0,1,2,2,1,14,0,0,0,1,0,0
,0,0,4,3,9,16,0,0,3,0,0,1,0,0,1,0,0,0,0,0,33,18,8,16,0,0,0,0,0,2,0,1,14,6,8,2
,0,0,0,0,1,1)
Data <- data.frame(Count,Country)
#create neighbour matrix
NB <- list()
NB$'East Timor' <- c(1,2,15)
NB$Australia <- c(1,2,15)
NB$'Sri Lanka' <-c(3,12,16)
NB$Bangladesh <-c(4,12,13,16)
NB$Philippines <- c(5,6,11,14,15,17)
NB$Taiwan <- c(5,6,11)
NB$Thailand <- c(7,8,10,12,13,14,15)
NB$Vietnam <- c(7,8,10,11,14,15)
NB$`South Korea` <- c(9,11)
NB$Cambodia <- c(7,8,10)
NB$China <- c(5,6,8,9,11,14)
NB$India <- c(3,4,7,12,13,15,16)
NB$Myanmar <- c(4,7,12,13,16)
NB$Malaysia <- c(5,7,8,11,14,15)
NB$Indonesia <- c(1,2,5,7,8,12,14,15)
NB$HighSeas2 <- c(3,4,12,13,16)
NB$HighSeas1 <- c(5,17)
#check levels and names match
all.equal(sort(names(NB)), sort(levels(Data$Country)))
#try fitting GAM
m1 <- gam(Data$Count ~ s(Data$Country, bs = 'mrf', xt = list(nb = NB)))