I'm new to R and in a bit of a jam while working on a project in R, specifically trying to fit a Lee-Carter model using the StMoMo package.
I'm attempting to create a
StMoMoData object using two datasets: one for mortality (
males.txt) and another for population data (
malespop.txt). Despite having matching years in both datasets, I'm encountering a perplexing error when trying to create a demogdata object : "Number of years doesn't match data."
I'm seeking some guidance on how to tackle this "Number of years" error within the context of fitting a Lee-Carter model.
Here's a snippet of the code I'm working with:
library(StMoMo) library(demography) # Read in mortality data men <- read.table("males.txt", header = TRUE, na.strings = ",") # Read in population data pop <- read.table("malespop.txt", header = TRUE, na.strings = ",") # Create a demogdata object men_demogdata <- demogdata(data = men, pop = pop, ages = 0:120, years = 1977:2019, type = "mortality") # Create a StMoMoData object mena <- StMoMoData(men_demogdata, series = "Male") #Fit an LC model LCfit <- fit(object = lc(), data = men, ages.fit = 0:120, years.fit = 1977 : 2019)
Any help or insights you can offer would be greatly appreciated!