JMbayes icon indicating copy to clipboard operation
JMbayes copied to clipboard

IndvPred_lme : Error in right_rows(newdata, newdata[[timeVar]], id, times_to_pred) : 'list' object cannot be coerced to type 'double'

Open jilljb18 opened this issue 3 years ago • 3 comments

I am using IndvPred_lme to cross-validate an lme model, which looks like this: final = lme(IHS_Ypd ~ L_S383D * (Encr + Trt), data = Boot.temp, random = ~ 1 | Plot, correlation = corARMA(form = ~ visit | Plot / Tind, p = 1))

I'm then trying to apply this model to new data, with different unique levels of Tind (different values of Plot could also occur by chance):

preds <- JMbayes::IndvPred_lme(final, newdata = Boot.test, timeVar = "visit")

I also tried this: final_light <- JMbayes::extract_lmeComponents(final, timeVar = "visit") preds <- JMbayes::IndvPred_lme(final_light, newdata = Boot.test, timeVar = "visit")

[side note: I'm not sure if converting to the light version is necessary]

Either way, I'm getting this error: Error in right_rows(newdata, newdata[[timeVar]], id, times_to_pred) : 'list' object cannot be coerced to type 'double'

I've tried converting 'visit' to a numeric (rather than the original integer), and also converting all characters to factors prior to splitting the data and fitting the model, and ensuring levels of Tind are appropriately unique in the training versus test set, but none of fixes the issue.

I'm guessing this is probably something simple, but I can't figure it out. I'm not an expert coder, so apologies for the possibly dumb question. Thanks!

jilljb18 avatar Nov 24 '21 03:11 jilljb18

This could be because you need to specify the times argument.

Best, Dimitris

From: jilljb18 @.> Sent: Wednesday, November 24, 2021 4:47 AM To: drizopoulos/JMbayes @.> Cc: Subscribed @.***> Subject: [drizopoulos/JMbayes] IndvPred_lme : Error in right_rows(newdata, newdata[[timeVar]], id, times_to_pred) : 'list' object cannot be coerced to type 'double' (Issue #88)

Waarschuwing: Deze e-mail is afkomstig van buiten de organisatie. Klik niet op links en open geen bijlagen, tenzij u de afzender herkent en weet dat de inhoud veilig is. Caution: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.

I am using IndvPred_lme to cross-validate an lme model, which looks like this: final = lme(IHS_Ypd ~ L_S383D * (Encr + Trt), data = Boot.temp, random = ~ 1 | Plot, correlation = corARMA(form = ~ visit | Plot / Tind, p = 1))

I'm then trying to apply this model to new data, with different unique levels of Tind (different values of Plot could also occur by chance):

preds <- JMbayes::IndvPred_lme(final, newdata = Boot.test, timeVar = "visit")

I also tried this: final_light <- JMbayes::extract_lmeComponents(final, timeVar = "visit") preds <- JMbayes::IndvPred_lme(final_light, newdata = Boot.test, timeVar = "visit")

[side note: I'm not sure if converting to the light version is necessary]

Either way, I'm getting this error: Error in right_rows(newdata, newdata[[timeVar]], id, times_to_pred) : 'list' object cannot be coerced to type 'double'

I've tried converting 'visit' to a numeric (rather than the original integer), and also converting all characters to factors prior to splitting the data and fitting the model, and ensuring levels of Tind are appropriately unique in the training versus test set, but none of fixes the issue.

I'm guessing this is probably something simple, but I can't figure it out. I'm not an expert coder, so apologies for the possibly dumb question. Thanks!

You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fdrizopoulos%2FJMbayes%2Fissues%2F88&data=04%7C01%7Cd.rizopoulos%40erasmusmc.nl%7C7c5ced1086904a78311808d9aefd1a8a%7C526638ba6af34b0fa532a1a511f4ac80%7C0%7C0%7C637733224371442669%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=WZHCYP4o4URiZYDAmwkbrNkGVZWeaRHMQCaPDwTK5PU%3D&reserved=0, or unsubscribehttps://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FADE7TT3HILZLQUYOS4KNSMDUNRN4DANCNFSM5IVBM6VA&data=04%7C01%7Cd.rizopoulos%40erasmusmc.nl%7C7c5ced1086904a78311808d9aefd1a8a%7C526638ba6af34b0fa532a1a511f4ac80%7C0%7C0%7C637733224371442669%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=cFC%2BXoRc4DWs87c8ZzgFv%2FCVskV5Gq6trWqp82cRysk%3D&reserved=0.

drizopoulos avatar Nov 24 '21 09:11 drizopoulos

Thanks for the reply.

I am just trying to predict for the times that are present in the Boot.test dataset, not forecast past those. Also (and unfortunately) the times (visit) values are not the same for each Tree, i.e. some trees are missing measurements/data for some 'visits'.

I just now tried adding 'times=Boot.test$visit'. This seems like it would at least only predict for the values within the Boot.temp data, but I'm guessing this is not what the function actually 'wants' and adding it doesn't prevent the error.

Just for the sake of trying something (even though this is not what I want), I added 'times = c(7,8)' and got this error: Error in col(ind) : a matrix-like object is required as argument to 'col' So I guess I'm unclear on what the 'times' argument should look like.

Lastly, again, just to try something, if I add 'all_times = TRUE' without the times argument, I get a different error: Error in m[i, , drop = FALSE] : subscript out of bounds Note again, that I don't actually want to predict for all times, as explained above.

Thanks again for your help!

jilljb18 avatar Nov 24 '21 18:11 jilljb18

Hello,

I am in the same situation as you, have you found a solution to your problem ?

Like you, when I try to use IndvPred_lme, I go this error : Error in col(ind) : a matrix-like object is required as argument to 'col'

Thanks in advance

deconinckflo avatar Jun 13 '22 14:06 deconinckflo