我在将Renshaw和Haberman模型与加拿大女性数据拟合时遇到困难。当我尝试拟合模型时,此错误标记出来。
Warning in fit.StMoMo(RH, data = CANfemaleinidata, ages.fit = ages.fit, : StMoMo: The model fitting didn't converge.
完整的上下文显示在reprex中。
代表
RH <- rh(link = "logit", cohortAgeFun = "1")
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)
canada <- hmd.mx("CAN", "username", "password", "Canada")
#> Warning in hmd.mx("CAN", "username", "password", "Canada"):
#> NAs introduced by coercion
CANfemale <- StMoMoData(canada, series = "female")
CANfemaleinidata <- central2initial(CANfemale)
ages.fit <- 55:89
wxt <- genWeightMat(ages = ages.fit, years = CANfemaleinidata$years,
clip = 3)
LCfitfemale <- fit(LC, data = CANfemaleinidata, 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
RHfitfemale <- fit(RH, data = CANfemaleinidata, ages.fit = ages.fit, wxt = wxt,
start.ax = LCfitfemale$ax, start.bx = LCfitfemale$bx, start.kt = LCfitfemale$kt)
#> StMoMo: The following cohorts have been zero weigthed: 1832 1833 1834 1954 1955 1956
#> StMoMo: Start fitting with gnm
#> Initialising
#> Running main iterations....................................................
#> ...........................................................................
#> ...........................................................................
#> ...........................................................................
#> ...........................................................................
#> ...........................................................................
#> .........................................................................
#> Done
#> Warning in gnmFit(modelTools = modelTools, y = y, constrain = constrain, : Fitting algorithm has either not converged or converged
#> to a non-solution of the likelihood equations.
#> Use exitInfo() for numerical details of last iteration.
#> StMoMo: Finish fitting with gnm
#> Warning in fit.StMoMo(RH, data = CANfemaleinidata, ages.fit = ages.fit, : StMoMo: The model fitting didn't converge.
这个错误特别奇怪的是,当我使用加拿大男性数据时,它不会发生(请参见下面的reprex)
CANmale <- StMoMoData(canada, series = "male")
CANmaleinidata <- central2initial(CANmale)
ages.fit <- 55:89
wxt <- genWeightMat(ages = ages.fit, years = CANmaleinidata$years,
clip = 3)
LCfitmale <- fit(LC, data = CANmaleinidata, 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
RHfitmale <- fit(RH, data = CANmaleinidata, ages.fit = ages.fit, wxt = wxt,
start.ax = LCfitmale$ax, start.bx = LCfitmale$bx, start.kt = LCfitmale$kt)
#> StMoMo: The following cohorts have been zero weigthed: 1832 1833 1834 1954 1955 1956
#> StMoMo: Start fitting with gnm
#> Initialising
#> Running main iterations.........................
#> Done
#> StMoMo: Finish fitting with gnm
我该如何解决?