DEV BY BADR ELHAMZAOUI (MEDIAS24) # Chargement des biblio nécessaires library(tidyverse) library(forecast) library(demogR) library(rstanarm) library(splines) # Data 2014-2024 annees <- seq(2014, 2024, by = 1) population_reelle <- c(33.8, 34.1, 34.5, 34.8, 35.2, 35.6, 36.0, 36.3, 36.7, 37.0, 36.3) # Réalité 2024 ISF <- c(2.21, 2.19, 2.10, 2.02, 1.95, 1.89, 1.84, 1.82, 1.80, 1.78, 1.76) # Fécondité observée mortalite <- seq(0.005, 0.01, length.out = length(annees)) # Hypothèse de mortalité croissante migration <- c(rep(-0.001, 5), rep(-0.002, 6)) # Migration nette négative # dataframe des données historiques data <- data.frame(annees = annees, population = population_reelle, ISF = ISF) # Modèle bayésien pour ajuster les tendances observées (population ~ année) - NB : cette étape pzut prendre plus de 3 heures de eunning du modèle) modele_bayesien <- stan_glm( population ~ poly(annees, 3, raw = TRUE), # Modèle polynomial data = data, family = gaussian(), prior = normal(0, 5), prior_intercept = normal(0, 5), chains = 4, iter = 2000, seed = 123 ) # Simulation des projections 2025-2050 (rgph 2014 VS rgph 2024) annees_proj <- seq(2025, 2050, by = 1) ISF_projete <- seq(1.76, 1.48, length.out = length(annees_proj)) # ISF projeté mortalite_projete <- seq(0.01, 0.015, length.out = length(annees_proj)) migration_projete <- seq(-0.002, -0.005, length.out = length(annees_proj)) # Calcul proje de population population_proj <- numeric(length(annees_proj)) population_proj[1] <- data$population[length(data$population)] # Point de départ (2024) for (i in 2:length(annees_proj)) { population_proj[i] <- population_proj[i - 1] * ( 1 + ISF_projete[i - 1] * 0.01 - mortalite_projete[i - 1] + migration_projete[i - 1] ) } # Fusion des données réelles et projetées projections <- data.frame( annees = c(annees, annees_proj), population = c(data$population, population_proj), ISF = c(ISF, ISF_projete) ) # pic démo population_max <- max(projections$population) annee_pic <- projections$annees[which.max(projections$population)] # OUTPUT year pic cat("Population maximale recalibrée :", round(population_max, 2), "millions en", annee_pic, "\n") #vPROJECTION PIC ggplot(projections, aes(x = annees, y = population)) + geom_line(color = "blue", size = 1.2) + geom_point(data = data, aes(x = annees, y = population), color = "red", size = 2) + labs( title = "Projections démographiques recalibrées (2014-2050)", x = "Année", y = "Population (en millions)" ) + annotate("text", x = annee_pic, y = population_max, label = paste("Pic en", annee_pic), vjust = -1, color = "blue") + theme_minimal()