Last year I explored Hidden Markov Models in RMark using R version 3.6.3. This forum question
http://www.phidot.org/forum/viewtopic.php?f=21&t=4195&p=13912&hilit=HMM#p13912
had a working example.
I have since updated R to version 4.1.3 and the code now returns the following error at the make.design.data step:
- Code: Select all
Error in `[<-.data.frame`(`*tmp*`, design.data$stratum == label, label, :
missing values are not allowed in subscripted assignments of data frames
In R, this error usually occurs when a column has a missing value (NA) or when indices that are used in a function are missing from the data. With HMMs in Mark, we of course specified 'strata.labels' that do not occur in the observed data.
Is there a solution to this other than going back to R3.6.3, where everything seems to work fine? I am using RMark 2.2.7. Reproducible example code (copied from the above link) follows here:
- Code: Select all
library(RMark)
# Add a few uncertainty events (event = '5') to the above input data
df = c('1010001',
'1050000', '1010000', '1010000', '1010100', '1000000', '1000001', '1000001',
'1000001', '1010105', '1050101', '1010101', '1050101', '1010101', '1010101',
'1010101', '1010101', '1010001', '1000001', '1000001', '1000001', '1010101',
'1010101', '1010101', '1050101', '1010101', '1010101', '1010201', '1010201',
'1010201', '1010201', '1010201', '1010201', '1010201', '1010201', '1010201',
'1010201', '1010201', '1010201', '1010201', '1010201', '1050201', '1010205',
'2010201', '2010000', '2000000', '2000000', '2000000', '2000000', '2000000',
'2050220', '2010221', '2010221', '2050221', '2010221', '2010221', '2010221',
'2010221', '2010521', '2010251', '2012221', '2012222', '2012222', '2012222',
'2012251', '5012221', '2012020', '2022010', '2025010', '2022010', '2022010',
'2052010', '2022010', '2022010', '2022010', '2022010', '2021010', '2021010',
'2021010', '2051010', '2051010', '5021010', '2001000', '2025010', '2021010',
'2021010')
df=as.data.frame(df); names(df) = "ch"; df$freq = 1; df$ch = as.character(df$ch)
head(df)
# 'event' is only for the uncertain observation - not the 'state' observations!
# Error in process.data: unused argument (events) if package marked is loaded in session
# states 3 & 4 = unobservable
dp = process.data(df, model = "HidMarkov", strata.labels = c("3", "4","1", "2"),
events = c("5"))
## create design data
ddl = make.design.data(dp)