library(reportsWS)
library(forecast)

# Select name and gender
name <- "Gillian"    # Always capitalize
sex <- "F"           # or "M"
names <- get_babyname(name, sex)

# Create time series and forecast
nbirths <- ts(names$n, start = 1880)
mod <- auto.arima(nbirths)
pred <- forecast(mod, h = 12) # 12 for 2025

Since 1880, r sum(nbirths, na.rm = TRUE) children have been named r name. The graph below breaks this number down by year showing the number of children named r name as a time series.

# Make plot
title <- paste0("Number of children named ", name)
all <- bind_as_xts(nbirths, pred) 
plot(all, main = title)

We modeled this time series with an r trim_whitespace(pred$method) model to predict the number of children that will be given the name r name in 2025.

data.frame(
  method = trim_whitespace(pred$method), 
  predicted_2025 = round(xts::last(pred$mean)))


rstudio/reportsWS documentation built on May 28, 2019, 5:42 a.m.