Missing values error for HidMarkov models in R version 4

posts related to the RMark library, which may not be of general interest to users of 'classic' MARK

Missing values error for HidMarkov models in R version 4

Postby chris_oosthuizen » Wed May 04, 2022 4:30 am

Hi all,

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)
chris_oosthuizen
 
Posts: 10
Joined: Wed Sep 12, 2012 10:37 am

Re: Missing values error for HidMarkov models in R version 4

Postby jlaake » Fri Jun 17, 2022 5:39 pm

Chris and I resolved this offline. Not quite sure why he was getting the error but it did not occur with the newer R4.2 version.
jlaake
 
Posts: 1417
Joined: Fri May 12, 2006 12:50 pm
Location: Escondido, CA


Return to RMark

Who is online

Users browsing this forum: No registered users and 12 guests