Skip to content

Instantly share code, notes, and snippets.

@ikashnitsky
Last active January 19, 2022 12:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ikashnitsky/35a0437d20c1c2e7f059e875ce2100b9 to your computer and use it in GitHub Desktop.
Save ikashnitsky/35a0437d20c1c2e7f059e875ce2100b9 to your computer and use it in GitHub Desktop.
Example of population size estimate using stationary assumption (Elon Musk) -- https://twitter.com/ikashnitsky/status/1483740904892608513
#===============================================================================
# 2022-01-19 -- twitter
# Musk stationary population estimate -- minimal US example
# Ilya Kashnitsky, ilya.kashnitsky@gmail.com, @ikashnitsky
#===============================================================================
library(tidyverse)
library(magrittr)
library(hrbrthemes)
source("https://gist.githubusercontent.com/ikashnitsky/35a0437d20c1c2e7f059e875ce2100b9/raw/a48c2b9441c2a7134ca55796087a15d6f69b501d/data.R")
elon %>%
ggplot(aes(year))+
geom_line(aes(y = pop/1e6))+
geom_line(aes(y = pop_elon/1e6), color = 2)+
scale_y_comma(limits = c(0, 3.8e2))+
theme_minimal(base_family = font_rc)+
labs(
y = "population size, million",
title = "United States population",
caption = "data @HMDatabase; design @ikashnitsky"
)+
annotate(
"text", x = c(1975, 1925), y = c(175, 335),
label = c(
"Actual\n(HMD exposures)",
"Elon Musk\n(stationary population\nassumption)"
),
hjust = 0, size = 5, color = 1:2, lineheight = .9,
family = "Roboto Slab"
)+
theme(
panel.grid.minor = element_blank(),
plot.title = element_text(family = "Roboto Slab", face = 2, size = 24)
)
elon <- structure(list(country = c("USA", "USA", "USA", "USA", "USA",
"USA", "USA", "USA", "USA", "USA", "USA", "USA", "USA", "USA",
"USA", "USA", "USA", "USA", "USA", "USA", "USA", "USA", "USA",
"USA", "USA", "USA", "USA", "USA", "USA", "USA", "USA", "USA",
"USA", "USA", "USA", "USA", "USA", "USA", "USA", "USA", "USA",
"USA", "USA", "USA", "USA", "USA", "USA", "USA", "USA", "USA",
"USA", "USA", "USA", "USA", "USA", "USA", "USA", "USA", "USA",
"USA", "USA", "USA", "USA", "USA", "USA", "USA", "USA", "USA",
"USA", "USA", "USA", "USA", "USA", "USA", "USA", "USA", "USA",
"USA", "USA", "USA", "USA", "USA", "USA", "USA", "USA", "USA",
"USA"), year = c(1933, 1934, 1935, 1936, 1937, 1938, 1939, 1940,
1941, 1942, 1943, 1944, 1945, 1946, 1947, 1948, 1949, 1950, 1951,
1952, 1953, 1954, 1955, 1956, 1957, 1958, 1959, 1960, 1961, 1962,
1963, 1964, 1965, 1966, 1967, 1968, 1969, 1970, 1971, 1972, 1973,
1974, 1975, 1976, 1977, 1978, 1979, 1980, 1981, 1982, 1983, 1984,
1985, 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
2018, 2019), ex = c(60.9, 60.19, 60.91, 60.35, 61.03, 62.39,
63.07, 63.22, 63.79, 64.54, 64.36, 65.06, 65.59, 66.13, 66.8,
67.22, 67.63, 68.06, 68.17, 68.38, 68.72, 69.5, 69.56, 69.64,
69.41, 69.67, 69.9, 69.82, 70.24, 70.11, 69.94, 70.19, 70.25,
70.21, 70.52, 70.21, 70.48, 70.74, 71.1, 71.18, 71.4, 71.96,
72.54, 72.85, 73.23, 73.41, 73.83, 73.74, 74.12, 74.47, 74.56,
74.68, 74.66, 74.74, 74.88, 74.85, 75.13, 75.4, 75.55, 75.81,
75.6, 75.77, 75.88, 76.2, 76.53, 76.69, 76.7, 76.84, 76.96, 77.03,
77.18, 77.58, 77.58, 77.86, 78.12, 78.22, 78.59, 78.79, 78.84,
78.97, 78.98, 79.05, 78.9, 78.88, 78.85, 79.01, 79.16), births = c(2307000,
2396000, 2377000, 2355000, 2413000, 2497000, 2466000, 2559000,
2703000, 2989000, 3103000, 2939000, 2858000, 3411000, 3817000,
3637000, 3649000, 3631000, 3823000, 3913000, 3965000, 4078000,
4104000, 4218000, 4308000, 4255000, 4312100, 4257850, 4268326,
4167362, 4098020, 4027490, 3760358, 3606274, 3520959, 3501564,
3600206, 3731386, 3555970, 3258411, 3136965, 3159958, 3144198,
3167788, 3326632, 3333279, 3494398, 3612258, 3629238, 3680537,
3638933, 3669141, 3760561, 3756547, 3809394, 3909510, 4040958,
4158212, 4110907, 4065014, 4000240, 3952767, 3899589, 3891494,
3880894, 3941553, 3959417, 4058814, 4025933, 4021726, 4089950,
4112052, 4138349, 4265555, 4316233, 4247694, 4130665, 3999386,
3953590, 3952841, 3932181, 3988076, 3978497, 3945875, 3855500,
3791712, 3747540), pop = c(125646795.97, 126417593.25, 127275490.41,
128090418.68, 128919363.94, 129888316.6, 130936956.17, 132025098.52,
133076174.61, 133815266.29, 133898142.13, 133160591.25, 134531764.38,
138918556.84, 143332205.85, 146078119.37, 148666278.52, 151103731.67,
153392495.79, 155735804.33, 158340995.75, 161231892.29, 164289373.65,
167338192.86, 170375859.72, 173356863.31, 177145278.53, 180045966.87,
182997916.78, 185806197.6, 188516714.7, 191123156.62, 193501045.07,
195565595.59, 197507002.95, 199411942.01, 201538667.89, 203998270.52,
206705011.44, 209117497.19, 211246250.2, 213244022.03, 215320048.73,
217432180.31, 219681639.03, 222009044.09, 224502352.85, 227019900.43,
229362034.02, 231554984.21, 233681308.83, 235741629.87, 237836065.7,
240021922.37, 242192730.65, 244408306.22, 246816766.69, 249645237.63,
252896076.64, 256343967.93, 259696304.31, 262907444.15, 266017730.22,
269129353.52, 272302839.87, 275477562.37, 278601578.17, 281619634.89,
284508037.8, 287170090.47, 289750154.28, 292415341.48, 295190146.17,
298029889.15, 300953950.3, 303834372.19, 306598132.92, 309148700.18,
311486536.4, 313731982.92, 315963779.42, 318263536.6, 320589378.25,
322851497.39, 324883738.74, 326493636.22, 327610213.04), pop_elon = c(140496300,
144215240, 144783070, 142124250, 147265390, 155787830, 155530620,
161779980, 172424370, 192910060, 199709080, 191211340, 187456220,
225569430, 254975600, 244479140, 246781870, 247125860, 260613910,
267570940, 272474800, 283421000, 285474240, 293741520, 299018280,
296445850, 301415790, 297283087, 299807218.24, 292173749.82,
286615518.8, 282689523.1, 264165149.5, 253196497.54, 248298028.68,
245844808.44, 253742518.88, 263958245.64, 252829467, 231933694.98,
223979301, 227390577.68, 228080122.92, 230773355.8, 243609261.36,
244696011.39, 257991404.34, 266367904.92, 268999120.56, 274089590.39,
271318844.48, 274011449.88, 280763484.26, 280764322.78, 285247422.72,
292626823.5, 303597174.54, 313529184.8, 310579023.85, 308168711.34,
302418144, 299501155.59, 295900813.32, 296531842.8, 297004817.82,
302277699.57, 303687283.9, 311879267.76, 309835803.68, 309793553.78,
315662341, 319012994.16, 321053115.42, 332116112.3, 337184121.96,
332254624.68, 324628962.35, 315111622.94, 311701035.6, 312155853.77,
310563655.38, 315257407.8, 313903413.3, 311250620, 304006175,
299583165.12, 296655266.4)), row.names = c(NA, -87L), class = c("tbl_df",
"tbl", "data.frame"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment