amvillegas / StMoMo

Stochastic Mortality Modelling
22 stars 6 forks source link

Error in UseMethod("predictLink") #21

Open victoriarty97 opened 5 years ago

victoriarty97 commented 5 years ago

When trying to fit the LC model using this package (LCfit <- fit(LC, data = data, ages.fit = ages.fit, wxt = wxt)) I get an error message reading:

Error in UseMethod("predictLink") : no applicable method for 'predictLink' applied to an object of class "c('double', 'numeric')"

Unsure how to fix this.

Here is my reprex:

[library("reprex")
library("demography")
Loading required package: forecast
This is demography 1.20 

Attaching package: ‘demography’

The following objects are masked _by_ ‘.GlobalEnv’:

    hmd.e0, hmd.mx, hmd.pop

library("StMoMo")
Loading required package: gnm

Attaching package: ‘StMoMo’

The following object is masked _by_ ‘.GlobalEnv’:

    fit

canada <- hmd.mx("CAN", "username", "password", "Canada")
Warning message:
In hmd.mx("CAN", "username", "password", "Canada") :
  NAs introduced by coercion
constLC <- function(ax, bx, kt, b0x, gc, wxt, ages){
+     +     + c1 <- mean(kt[1, ], na.rm = TRUE)
+     +     + c2 <- sum(bx[, 1], na.rm = TRUE)
+     +     + list(ax = ax + c1 * bx, bx = bx / c2, kt = c2 * (kt - c1))
+ }
LC <- StMoMo(link = "logit", staticAgeFun = TRUE, periodAgeFun = "NP",
+ constFun = constLC)
CANStMoMo <- StMoMoData(canada, series = "total")
summary(CANStMoMo)
Mortality data for Canada
    Series:  total
    Years: 1921 - 2011
    Ages:  0 - 110
    Exposure:  central 
CANStMoMoinitial <- central2initial(CANStMoMo)
wxt <- genWeightMat(ages = ages.fit, years = CANStMoMoinitial$years,
+ clip = 3)
LCfit <- fit(LC, data = CANStMoMoinitial, ages.fit = ages.fit, wxt = wxt)
StMoMo: The following cohorts have been zero weigthed: 1832 1833 1834 1954 1955 1956 
StMoMo: Start fitting with gnm
Initialising
Running start-up iterations..
Running main iterations......
Done
StMoMo: Finish fitting with gnm
 Show Traceback

 Rerun with Debug
 Error in UseMethod("predictLink") : 
  no applicable method for 'predictLink' applied to an object of class "c('double', 'numeric')" 
#> Error: <text>:3:9: unexpected symbol
#> 2: library("demography")
#> 3: Loading required
#>            ^](url)