Greetings!

I need really need your help. What is problem? Which section of the code should I fix? Who has any idea? Please, help me. This is crucial for my study.

*Code starts

# Required packages

install.packages("readxl")

install.packages("demography")

install.packages("forecast")

# Load the packages

library(demography)

library(forecast)

library(readxl)

# Specify the file path

file_path <- "D:/maledatafer.xlsx"

# Read the Excel file

lee_carter_data <- readxl::read_excel(file_path, sheet = 1)

# Extract the years and population data

years <- lee_carter_data$Years

population_data <- lee_carter_data[, -1] # Exclude the first column (Years)

# Convert the data to a matrix

mortality_matrix <- as.matrix(population_data)

# Check dimensions and transpose if needed

if (nrow(mortality_matrix) < ncol(mortality_matrix)) {

mortality_matrix <- t(mortality_matrix)

}

# Convert the matrix to a 'demogdata' object

demog_data <- demogdata(mortality_matrix, pop = colSums(mortality_matrix))

# Fit the Lee-Carter model using the demography package

lc_model <- lca(demog_data)

# 'h' is the number of periods (years) to forecast

forecast_result <- forecast(lc_model, h = 2)

plot(forecast_result)

*Code ends

Problem is:

Error in if (nrow(pop) != p | ncol(pop) != n) stop("data and pop are of different size") :

argument is of length zero

What should I do? I really appreciate your help and support.

Thank you