0

I want to make predictions with differents models in the same data using the package MortalityLaws. I have the model's names in a data frame as follow

models <- data.frame(models=c("model1", "model2", "model3"))

where

age <- 45:75
Dx <- ahmd$Dx[paste(x), "1950"]
Ex <- ahmd$Ex[paste(x), "1950"]

model1 <- MortalityLaw(x = age, Dx = Dx, Ex = Ex, law = 'quadratic')
model2 <- MortalityLaw(x = age, Dx = Dx, Ex = Ex, law = 'kannisto_makeham')
model3 <- MortalityLaw(x = age, Dx = Dx, Ex = Ex, law = 'ggompertz')

I use the follow function

prediction_model1 <- predict(models$models[1] , x=80:110)

To make predictions for the first model, but it doesn´t make predictions.

How can I solve my problem?

bubleskmy
  • 131
  • 1
  • 9
  • Pleases show a small reproducible example – akrun Feb 11 '20 at 19:23
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Feb 11 '20 at 19:24
  • Print out `models`. It probably does not contain what you think since it is just a character vector that has been converted to a factor. Did it not give you an error message? – dcarlson Feb 11 '20 at 21:25

1 Answers1

0

As per the MortalityLaws package manual (https://cran.rproject.org/web/packages/MortalityLaws/MortalityLaws.pdf)

To predict, prediction_model1 <- predict(model1, x=80:110) should do the trick.

The one you are using is the value(model1) from model data frame, whereas the prediction_model1 needs to take model1(the data frame) as value for prediction.

shome
  • 1,342
  • 1
  • 12
  • 30