mhunter1 / dynr

Dynamic Modeling in R
5 stars 6 forks source link

Make `dynr.data()` smarter for the `id` argument #247

Open mhunter1 opened 4 years ago

mhunter1 commented 4 years ago

@meng-chen-2013 had an issue related to the difference between

dataOU <- dynr.data(data=data.frame(V1=r1d_obs[-1], time=seq(dt,T,by=dt)), id=1, time="time", observed="V1")

which gave insane results and

dataOU <- dynr.data(data=data.frame(V1=r1d_obs[-1], time=seq(dt,T,by=dt), ID=1), id="ID", time="time", observed="V1")

which worked fine. The former chunk of code interpreted the id argument as the first column of the data (the outcome variable), whereas Meng wanted it to mean that all IDs in this data set were 1.

I propose we could have the id argument do a bit of interpretation.

if(length(id) == 1 && is.character(id)) # id is the name of a column
if(length(id) == 1 && is.numeric(id)) # id is a single ID number
if(length(id) == nrow(observed)) # id is the ID associated with each row