diff --git a/DESCRIPTION b/DESCRIPTION index 4baa694..6fbb690 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: babynames -Title: US Baby Names 1880-2017 -Version: 1.0.1 -Authors@R: +Title: US Baby Names 1880-2023 +Version: 1.0.1.9000 +Authors@R: c(person(given = "Hadley", family = "Wickham", role = c("aut", "cre"), @@ -14,13 +14,13 @@ License: CC0 URL: https://github.com/hadley/babynames BugReports: https://github.com/hadley/babynames/issues Depends: - R (>= 2.10) + R (>= 3.5) Imports: tibble -Suggests: +Suggests: testthat (>= 3.0.0) Encoding: UTF-8 LazyData: true LazyDataCompression: xz -RoxygenNote: 7.1.1 +RoxygenNote: 7.3.2 Config/testthat/edition: 3 diff --git a/data-raw/USAtotbirthsRR.txt b/data-raw/USAtotbirthsRR.txt new file mode 100644 index 0000000..c9484ae --- /dev/null +++ b/data-raw/USAtotbirthsRR.txt @@ -0,0 +1,93 @@ +United States, Total live births +Last modified: 14/01/2025 +Year Total +1933 2081231.93 +1934 2167635.98 +1935 2155105.01 +1936 2144790.00 +1937 2203336.98 +1938 2286961.95 +1939 2265587.99 +1940 2360398.98 +1941 2513426.98 +1942 2808995.97 +1943 2934860.00 +1944 2794800.02 +1945 2735456.03 +1946 3288671.99 +1947 3699940.00 +1948 3535067.99 +1949 3559528.98 +1950 3554148.97 +1951 3750850.03 +1952 3846985.97 +1953 3902119.94 +1954 4017362.02 +1955 4047294.99 +1956 4163090.02 +1957 4254784.00 +1958 4203812.03 +1959 4244796.00 +1960 4257850.00 +1961 4268325.99 +1962 4167362.00 +1963 4098020.00 +1964 4027490.00 +1965 3760358.00 +1966 3606274.00 +1967 3520959.00 +1968 3501564.00 +1969 3600206.00 +1970 3731386.00 +1971 3555970.00 +1972 3258411.00 +1973 3136965.00 +1974 3159958.00 +1975 3144198.00 +1976 3167788.00 +1977 3326632.00 +1978 3333279.00 +1979 3494398.00 +1980 3612258.00 +1981 3629238.00 +1982 3680537.00 +1983 3638933.00 +1984 3669141.00 +1985 3760561.00 +1986 3756547.00 +1987 3809394.00 +1988 3909510.00 +1989 4040958.00 +1990 4158212.00 +1991 4110907.00 +1992 4065014.00 +1993 4000240.00 +1994 3952767.00 +1995 3899589.00 +1996 3891494.00 +1997 3880894.00 +1998 3941553.00 +1999 3959417.00 +2000 4058814.00 +2001 4025933.00 +2002 4021726.00 +2003 4089949.99 +2004 4112052.00 +2005 4138349.01 +2006 4265555.00 +2007 4316233.00 +2008 4247694.00 +2009 4130665.01 +2010 3999385.99 +2011 3953590.01 +2012 3952841.00 +2013 3932181.00 +2014 3988076.01 +2015 3978497.01 +2016 3945875.00 +2017 3855500.00 +2018 3791712.00 +2019 3747540.00 +2020 3613647.01 +2021 3664292.01 +2022 3667757.99 diff --git a/data-raw/applicants.R b/data-raw/applicants.R index 0dd8cc1..0da155b 100644 --- a/data-raw/applicants.R +++ b/data-raw/applicants.R @@ -8,17 +8,21 @@ library(usethis) page <- read_html("https://www.ssa.gov/oact/babynames/numberUSbirths.html") -ssa <- page %>% html_nodes("table") %>% .[[2]] %>% html_table() %>% tbl_df() +ssa <- page |> + html_nodes("table") |> + html_table() |> + _[[1]] |> + tibble::as_tibble() names(ssa) <- c("year", "M", "F", "total") ssa$total <- NULL ssa$M <- parse_number(ssa$M) ssa$F <- parse_number(ssa$F) -applicants <- ssa %>% - gather(sex, n_all, M:F) %>% - arrange(year, sex) %>% - mutate(n_all = as.integer(n_all)) %>% +applicants <- ssa |> + gather(sex, n_all, M:F) |> + arrange(year, sex) |> + mutate(n_all = as.integer(n_all)) |> arrange(year, sex) write_csv(applicants, "data-raw/applicants.csv") diff --git a/data-raw/applicants.csv b/data-raw/applicants.csv index 1b89bc3..21c52c7 100644 --- a/data-raw/applicants.csv +++ b/data-raw/applicants.csv @@ -1,277 +1,289 @@ year,sex,n_all 1880,F,97605 -1880,M,118400 +1880,M,118399 1881,F,98855 -1881,M,108282 -1882,F,115695 +1881,M,108276 +1882,F,115694 1882,M,122031 -1883,F,120059 -1883,M,112477 -1884,F,137586 +1883,F,120060 +1883,M,112475 +1884,F,137585 1884,M,122738 -1885,F,141948 +1885,F,141947 1885,M,115945 -1886,F,153735 +1886,F,153734 1886,M,119041 -1887,F,155422 -1887,M,109313 +1887,F,155423 +1887,M,109311 1888,F,189445 -1888,M,129906 -1889,F,189219 +1888,M,129907 +1889,F,189218 1889,M,119032 -1890,F,201661 -1890,M,119701 +1890,F,201663 +1890,M,119700 1891,F,196566 1891,M,109265 1892,F,224913 -1892,M,131453 +1892,M,131452 1893,F,225232 1893,M,121041 -1894,F,235971 -1894,M,124893 +1894,F,235972 +1894,M,124892 1895,F,247106 -1895,M,126643 +1895,M,126642 1896,F,251993 -1896,M,129071 +1896,M,129070 1897,F,248275 1897,M,121942 -1898,F,274144 -1898,M,132104 -1899,F,247490 -1899,M,115193 -1900,F,317752 -1900,M,162133 +1898,F,274146 +1898,M,132099 +1899,F,247489 +1899,M,115194 +1900,F,317738 +1900,M,162124 1901,F,254229 -1901,M,115595 -1902,F,280334 +1901,M,115592 +1902,F,280330 1902,M,132750 1903,F,278196 -1903,M,129326 -1904,F,292436 -1904,M,138508 -1905,F,309865 -1905,M,143238 -1906,F,313440 -1906,M,144071 -1907,F,337434 -1907,M,158587 -1908,F,354531 -1908,M,166368 -1909,F,368096 -1909,M,176867 +1903,M,129322 +1904,F,292435 +1904,M,138503 +1905,F,309863 +1905,M,143233 +1906,F,313434 +1906,M,144066 +1907,F,337433 +1907,M,158584 +1908,F,354530 +1908,M,166367 +1909,F,368094 +1909,M,176863 1910,F,419526 -1910,M,208521 -1911,F,441818 +1910,M,208516 +1911,F,441817 1911,M,241395 -1912,F,586712 -1912,M,451457 -1913,F,654913 +1912,F,586715 +1912,M,451456 +1913,F,654914 1913,M,536247 -1914,F,796619 -1914,M,683325 -1915,F,1023876 -1915,M,880940 -1916,F,1085721 -1916,M,923257 -1917,F,1123698 -1917,M,959325 -1918,F,1202365 -1918,M,1048674 -1919,F,1174648 -1919,M,1015337 -1920,F,1244039 -1920,M,1100817 -1921,F,1279711 -1921,M,1137940 -1922,F,1247556 -1922,M,1125261 -1923,F,1252460 -1923,M,1132325 -1924,F,1295706 -1924,M,1169066 -1925,F,1263075 -1925,M,1151445 -1926,F,1230152 -1926,M,1145506 -1927,F,1236397 -1927,M,1161855 -1928,F,1195463 -1928,M,1141171 -1929,F,1157521 -1929,M,1107538 -1930,F,1166423 -1930,M,1129422 -1931,F,1103625 -1931,M,1069568 -1932,F,1106222 -1932,M,1074289 -1933,F,1045936 -1933,M,1020008 -1934,F,1082225 -1934,M,1061738 -1935,F,1086706 -1935,M,1069387 -1936,F,1077491 -1936,M,1064170 -1937,F,1101762 -1937,M,1093483 -1938,F,1141359 -1938,M,1136302 -1939,F,1134043 -1939,M,1133162 -1940,F,1181249 -1940,M,1186022 -1941,F,1245857 -1941,M,1254654 -1942,F,1390394 -1942,M,1408070 -1943,F,1435274 -1943,M,1454311 -1944,F,1366455 -1944,M,1388968 -1945,F,1346064 -1945,M,1371285 -1946,F,1612845 -1946,M,1650220 -1947,F,1817823 -1947,M,1857382 -1948,F,1742576 -1948,M,1782564 -1949,F,1755492 -1949,M,1801835 -1950,F,1758618 -1950,M,1819067 -1951,F,1847277 -1951,M,1911828 -1952,F,1902276 -1952,M,1974199 -1953,F,1929099 -1953,M,2001256 -1954,F,1990839 -1954,M,2068413 -1955,F,2004694 -1955,M,2089594 -1956,F,2059267 -1956,M,2144575 -1957,F,2097547 -1957,M,2187459 -1958,F,2065020 -1958,M,2153039 -1959,F,2078511 -1959,M,2166256 -1960,F,2079841 -1960,M,2165696 -1961,F,2076400 -1961,M,2155956 -1962,F,2026983 -1962,M,2102051 -1963,F,1987940 -1963,M,2065187 -1964,F,1957248 -1964,M,2027330 -1965,F,1827379 -1965,M,1895210 -1966,F,1755580 -1966,M,1817912 -1967,F,1716699 -1967,M,1779774 -1968,F,1709549 -1968,M,1776069 -1969,F,1762722 -1969,M,1829979 -1970,F,1831889 -1970,M,1905622 -1971,F,1752365 -1971,M,1818381 -1972,F,1612464 -1972,M,1674675 -1973,F,1554035 -1973,M,1614211 -1974,F,1566138 -1974,M,1630740 -1975,F,1560738 -1975,M,1623029 -1976,F,1571864 -1976,M,1633225 -1977,F,1644926 -1977,M,1709859 -1978,F,1643789 -1978,M,1709099 -1979,F,1723133 -1979,M,1791825 -1980,F,1780361 -1980,M,1855024 -1981,F,1788234 -1981,M,1862416 -1982,F,1813985 -1982,M,1887126 -1983,F,1789354 -1983,M,1863331 -1984,F,1802890 -1984,M,1876225 -1985,F,1845903 -1985,M,1923822 -1986,F,1845046 -1986,M,1920958 -1987,F,1873831 -1987,M,1949471 -1988,F,1922580 -1988,M,2001329 -1989,F,1991890 -1989,M,2095455 -1990,F,2053962 -1990,M,2151160 -1991,F,2033116 -1991,M,2119192 -1992,F,2004297 -1992,M,2098620 -1993,F,1971175 -1993,M,2064960 -1994,F,1949024 -1994,M,2037946 -1995,F,1921218 -1995,M,2010995 -1996,F,1916882 -1996,M,2003372 -1997,F,1908808 -1997,M,1997337 -1998,F,1938008 -1998,M,2027136 -1999,F,1946204 -1999,M,2038346 -2000,F,1994881 -2000,M,2087391 -2001,F,1980040 -2001,M,2067422 -2002,F,1973957 -2002,M,2065531 -2003,F,2005406 -2003,M,2100052 -2004,F,2016585 -2004,M,2112190 -2005,F,2028174 -2005,M,2126034 -2006,F,2089049 -2006,M,2190837 -2007,F,2114797 -2007,M,2213423 -2008,F,2080929 -2008,M,2178453 -2009,F,2022977 -2009,M,2118953 -2010,F,1958284 -2010,M,2052122 -2011,F,1935047 -2011,M,2028589 -2012,F,1936239 -2012,M,2025890 -2013,F,1923856 -2013,M,2016731 -2014,F,1951652 -2014,M,2044378 -2015,F,1945317 -2015,M,2038331 -2016,F,1928438 -2016,M,2017790 -2017,F,1874899 -2017,M,1963290 +1914,F,796628 +1914,M,683320 +1915,F,1023862 +1915,M,880925 +1916,F,1085716 +1916,M,923241 +1917,F,1123689 +1917,M,959307 +1918,F,1202356 +1918,M,1048651 +1919,F,1174637 +1919,M,1015326 +1920,F,1244033 +1920,M,1100782 +1921,F,1279718 +1921,M,1137930 +1922,F,1247576 +1922,M,1125197 +1923,F,1252464 +1923,M,1132274 +1924,F,1295673 +1924,M,1169032 +1925,F,1263079 +1925,M,1151420 +1926,F,1230173 +1926,M,1145443 +1927,F,1236441 +1927,M,1161918 +1928,F,1195532 +1928,M,1141164 +1929,F,1157552 +1929,M,1107607 +1930,F,1166456 +1930,M,1129513 +1931,F,1103718 +1931,M,1069775 +1932,F,1106297 +1932,M,1074434 +1933,F,1046039 +1933,M,1020192 +1934,F,1082341 +1934,M,1061935 +1935,F,1086768 +1935,M,1069593 +1936,F,1077556 +1936,M,1064299 +1937,F,1101846 +1937,M,1093644 +1938,F,1141451 +1938,M,1136492 +1939,F,1134069 +1939,M,1133305 +1940,F,1181346 +1940,M,1186169 +1941,F,1245992 +1941,M,1254859 +1942,F,1390474 +1942,M,1408298 +1943,F,1435403 +1943,M,1454616 +1944,F,1366527 +1944,M,1389159 +1945,F,1346111 +1945,M,1371451 +1946,F,1612905 +1946,M,1650391 +1947,F,1817871 +1947,M,1857580 +1948,F,1742683 +1948,M,1782748 +1949,F,1755515 +1949,M,1802001 +1950,F,1758529 +1950,M,1818806 +1951,F,1847272 +1951,M,1911680 +1952,F,1901993 +1952,M,1973288 +1953,F,1929506 +1953,M,2002214 +1954,F,1990843 +1954,M,2069135 +1955,F,2004901 +1955,M,2090260 +1956,F,2059534 +1956,M,2146229 +1957,F,2098135 +1957,M,2188901 +1958,F,2065751 +1958,M,2154872 +1959,F,2078611 +1959,M,2166475 +1960,F,2079741 +1960,M,2165354 +1961,F,2077143 +1961,M,2156992 +1962,F,2026891 +1962,M,2101687 +1963,F,1988078 +1963,M,2064633 +1964,F,1957358 +1964,M,2027035 +1965,F,1827463 +1965,M,1894602 +1966,F,1755771 +1966,M,1817631 +1967,F,1716836 +1967,M,1779431 +1968,F,1709684 +1968,M,1775439 +1969,F,1762735 +1969,M,1829161 +1970,F,1831855 +1970,M,1904778 +1971,F,1752596 +1971,M,1817868 +1972,F,1612552 +1972,M,1674047 +1973,F,1554107 +1973,M,1613640 +1974,F,1566255 +1974,M,1630250 +1975,F,1560867 +1975,M,1622400 +1976,F,1571897 +1976,M,1632590 +1977,F,1645001 +1977,M,1709358 +1978,F,1643893 +1978,M,1708609 +1979,F,1723277 +1979,M,1791321 +1980,F,1780645 +1980,M,1854762 +1981,F,1788511 +1981,M,1862382 +1982,F,1814286 +1982,M,1887182 +1983,F,1789670 +1983,M,1863586 +1984,F,1803315 +1984,M,1876702 +1985,F,1846316 +1985,M,1924408 +1986,F,1845491 +1986,M,1921688 +1987,F,1874217 +1987,M,1950208 +1988,F,1923113 +1988,M,2002269 +1989,F,1992183 +1989,M,2095982 +1990,F,2054400 +1990,M,2152030 +1991,F,2033422 +1991,M,2119686 +1992,F,2004676 +1992,M,2099169 +1993,F,1971534 +1993,M,2065518 +1994,F,1949381 +1994,M,2038349 +1995,F,1921557 +1995,M,2011365 +1996,F,1917238 +1996,M,2003728 +1997,F,1909245 +1997,M,1997783 +1998,F,1938504 +1998,M,2027644 +1999,F,1946801 +1999,M,2039003 +2000,F,1995743 +2000,M,2088325 +2001,F,1980939 +2001,M,2068408 +2002,F,1975012 +2002,M,2066658 +2003,F,2006445 +2003,M,2101163 +2004,F,2017809 +2004,M,2113357 +2005,F,2029572 +2005,M,2127339 +2006,F,2090521 +2006,M,2192365 +2007,F,2116502 +2007,M,2215072 +2008,F,2082870 +2008,M,2180420 +2009,F,2025080 +2009,M,2120914 +2010,F,1960686 +2010,M,2054412 +2011,F,1937692 +2011,M,2031414 +2012,F,1939467 +2012,M,2029180 +2013,F,1927676 +2013,M,2020699 +2014,F,1956322 +2014,M,2049216 +2015,F,1950871 +2015,M,2044439 +2016,F,1935879 +2016,M,2025629 +2017,F,1889159 +2017,M,1979121 +2018,F,1859655 +2018,M,1943744 +2019,F,1834876 +2019,M,1921774 +2020,F,1767691 +2020,M,1849670 +2021,F,1791567 +2021,M,1873605 +2022,F,1793069 +2022,M,1872977 +2023,F,1749200 +2023,M,1831150 diff --git a/data-raw/babynames_sample.csv b/data-raw/babynames_sample.csv index 1cfebf7..1653e9c 100644 --- a/data-raw/babynames_sample.csv +++ b/data-raw/babynames_sample.csv @@ -1,55 +1,53 @@ year,sex,name,n,prop -1898,F,Catherine,1705,0.00621936 -1901,F,Ruth,3974,0.01563158 -1910,F,Mattie,1687,0.0040212 -1914,M,Stanley,3559,0.00520836 -1922,M,Gene,1089,9.6778e-4 -1923,F,Billie,1247,9.9564e-4 -1926,F,Louise,7983,0.00648944 -1928,F,Imogene,1315,0.00109999 -1929,F,Dorothy,31478,0.02719432 -1930,F,Ada,1040,8.9161e-4 -1932,F,Constance,2492,0.00225271 -1950,F,Katherine,6204,0.00352777 -1953,M,Lonnie,1923,9.609e-4 -1954,M,Darryl,1330,6.4301e-4 -1955,M,Jon,3054,0.00146153 -1959,M,Don,3620,0.00167109 -1960,M,Jackie,1367,6.3121e-4 -1961,M,Tom,4720,0.00218928 -1963,F,Allison,1434,7.2135e-4 -1964,M,Calvin,2253,0.00111131 -1965,M,Brian,24555,0.01295635 -1968,F,Andrea,7089,0.00414671 -1969,F,Annette,3105,0.00176148 -1970,M,Steven,26821,0.01407467 -1973,M,Billy,3444,0.00213355 -1974,F,Shawn,1271,8.1155e-4 -1976,F,Rebecca,14491,0.00921899 -1976,M,Christian,2267,0.00138805 -1979,F,Ruth,1201,6.9699e-4 -1980,F,Rhonda,1534,8.6162e-4 -1980,M,Adam,18873,0.01017399 -1984,F,Beth,1632,9.0521e-4 -1985,M,Isaac,1670,8.6806e-4 -1989,F,Meredith,1700,8.5346e-4 -1990,M,Drew,1953,9.0788e-4 -1991,M,Preston,1426,6.729e-4 -1993,F,Valerie,2176,0.00110391 -1994,F,Chelsey,1654,8.4863e-4 -1995,F,Kassandra,1607,8.3645e-4 -1996,F,Kaitlin,3135,0.00163547 -1996,M,Allen,1467,7.3227e-4 -1998,M,Peter,3386,0.00167034 -2000,F,Haylee,1261,6.3212e-4 -2002,F,Adrianna,1445,7.3203e-4 -2002,M,Francisco,2741,0.00132702 -2003,M,Malik,1505,7.1665e-4 -2005,M,Raul,1332,6.2652e-4 -2007,M,Griffin,1485,6.7091e-4 -2010,F,Andrea,3567,0.00182149 -2010,M,Kyler,1284,6.2569e-4 -2011,F,Addison,9297,0.0048045300000000004 -2012,F,Lilly,2785,0.00143836 -2013,M,Jayce,2661,0.00131946 -2014,F,Clara,2849,0.00145979 +1898,F,Louise,1693,0.00617554 +1901,F,Marie,3157,0.01241794 +1910,F,Ella,1587,0.00378284 +1914,M,Herbert,3253,0.00476058 +1922,M,Orville,1022,9.0829e-4 +1923,F,Delores,1181,9.4294e-4 +1926,F,Phyllis,6921,0.00562604 +1928,F,Ada,1213,0.00101461 +1929,F,Ruth,16021,0.01384041 +1930,F,Marcella,1035,8.873e-4 +1932,F,Eva,2522,0.00227968 +1950,F,Phyllis,6695,0.00380716 +1953,M,Dan,2166,0.0010818 +1954,M,Jim,1593,7.6989e-4 +1955,M,Allen,4742,0.00226862 +1959,F,Alicia,1365,6.5669e-4 +1959,M,Ricky,13215,0.00609977 +1960,M,Brad,2649,0.00122336 +1961,M,Robert,72950,0.03382025 +1963,F,Alice,3067,0.0015427 +1964,M,Tony,7196,0.00355001 +1970,F,Joan,1308,7.1403e-4 +1972,F,Sabrina,1879,0.00116523 +1974,F,Dana,5159,0.00329384 +1975,M,Heath,1204,7.4211e-4 +1977,M,Ian,2287,0.00133793 +1979,F,Andrea,10336,0.00599787 +1979,M,Samuel,5687,0.00317475 +1982,F,Tara,6524,0.0035959 +1988,F,Trisha,1067,5.5483e-4 +1990,F,Meghan,3695,0.00179858 +1992,F,Jessie,1096,5.4672e-4 +1993,M,Kevin,19083,0.00923884 +1994,M,Vincent,3603,0.00176761 +1995,M,Spencer,3618,0.00179878 +1997,M,Kaleb,1793,8.9749e-4 +2000,M,Avery,1370,6.5603e-4 +2001,F,Tiffany,2690,0.00135794 +2001,M,Shawn,2628,0.00127054 +2003,F,Paris,1160,5.7814e-4 +2004,F,Avery,4044,0.00200415 +2004,M,Brock,1349,6.3832e-4 +2005,F,Mia,10844,0.005343 +2009,F,Crystal,1160,5.7282e-4 +2009,M,Carson,4997,0.00235606 +2014,M,Riley,2446,0.00119363 +2015,F,Quinn,3094,0.00158596 +2016,M,Nathan,7997,0.00394791 +2018,F,Ariel,1828,9.8298e-4 +2018,M,Jacob,11878,0.00611089 +2020,M,Zander,1193,6.4498e-4 +2021,F,Angela,1281,7.1502e-4 diff --git a/data-raw/births.R b/data-raw/births.R index 57cf380..1b9fe3f 100644 --- a/data-raw/births.R +++ b/data-raw/births.R @@ -5,53 +5,44 @@ library(usethis) # 1909 - 2001 # Source: https://www2.census.gov/library/publications/2004/compendia/statab/123ed/hist/02HS0013.xls if (!file.exists("data-raw/02HS0013.xls")) { - download.file("https://www2.census.gov/library/publications/2004/compendia/statab/123ed/hist/02HS0013.xls", "data-raw/02HS0013.xls") + download.file( + "https://www2.census.gov/library/publications/2004/compendia/statab/123ed/hist/02HS0013.xls", + "data-raw/02HS0013.xls" + ) } -raw <- readxl::read_excel('data-raw/02HS0013.xls', +raw <- readxl::read_excel( + 'data-raw/02HS0013.xls', range = "A16:B117", col_names = FALSE, na = "(NA)" ) -births <- raw %>% +births <- raw |> transmute( - year = parse_integer(X__1), - births = X__2 * 1e3) %>% + year = parse_integer(`...1`), + births = `...2` * 1e3 + ) |> filter(!is.na(births)) -# 2002 - 2012 Manually extracted from -# http://www.cdc.gov/nchs/data/nvsr/nvsr62/nvsr62_09.pdf, page 50 (Table 21) -# 2002 - 2015 manually extracted from -# https://www.cdc.gov/nchs/data/nvsr/nvsr66/nvsr66_01.pdf -# 2016 - 2017 manually extracted from -# https://www.cdc.gov/nchs/data/nvsr/nvsr67/nvsr67_08-508.pdf, page 12 (Table 1) -recent <- tribble( - ~year, ~births, - 2002, 4021726, - 2003, 4089950, - 2004, 4112052, - 2005, 4138349, - 2006, 4265555, - 2007, 4316233, - 2008, 4247694, - 2009, 4130665, - 2010, 3999386, - 2011, 3953590, - 2012, 3952841, - 2013, 3932181, - 2014, 3988076, - 2015, 3978497, - 2016, 3945875, - 2017, 3855500 -) -births <- births %>% - bind_rows(recent) %>% +# Alternative source: 1959-2022 available from humanfertility.org +# Before 1959, these data exclude Alaska and Hawaii, so previous source used. +# From 1959, the two data sets match closely +# Data: https://www.humanfertility.org/File/GetDocument/Files/USA/20250130/USAtotbirthsRR.txt +# Documentation: https://www.humanfertility.org/File/GetDocumentFree/Docs/USA/USAcom.pdf +# (Free account needed for download) + +births2 <- readr::read_table("data-raw/USAtotbirthsRR.txt", skip = 2) |> + select(year = Year, births = Total) + +births <- bind_rows( + births |> filter(year <= 1958), + births2 |> filter(year >= 1959) +) |> mutate( year = as.integer(year), births = as.integer(births) - ) %>% - arrange(year) + ) write_csv(births, "data-raw/births.csv") usethis::use_data(births, overwrite = TRUE, compress = 'xz') diff --git a/data-raw/births.csv b/data-raw/births.csv index 07dce36..deb7489 100644 --- a/data-raw/births.csv +++ b/data-raw/births.csv @@ -51,7 +51,7 @@ year,births 1958,4255000 1959,4244796 1960,4257850 -1961,4268326 +1961,4268325 1962,4167362 1963,4098020 1964,4027490 @@ -90,17 +90,17 @@ year,births 1997,3880894 1998,3941553 1999,3959417 -2000,4059000 -2001,4026000 +2000,4058814 +2001,4025933 2002,4021726 -2003,4089950 +2003,4089949 2004,4112052 2005,4138349 2006,4265555 2007,4316233 2008,4247694 2009,4130665 -2010,3999386 +2010,3999385 2011,3953590 2012,3952841 2013,3932181 @@ -108,3 +108,8 @@ year,births 2015,3978497 2016,3945875 2017,3855500 +2018,3791712 +2019,3747540 +2020,3613647 +2021,3664292 +2022,3667757 diff --git a/data-raw/lifetables.R b/data-raw/lifetables.R index 12d16e4..0e23b1e 100644 --- a/data-raw/lifetables.R +++ b/data-raw/lifetables.R @@ -4,25 +4,32 @@ library(tidyr) library(dplyr) library(usethis) -get_lifetables <- function(year){ +get_lifetables <- function(year) { url <- "http://www.ssa.gov/oact/NOTES/as120/LifeTables_Tbl_7_%s.html" - tab <- xml2::read_html(sprintf(url, year)) %>% rvest::html_table(fill = TRUE) %>% {.[[2]]} + tab <- xml2::read_html(sprintf(url, year)) |> rvest::html_table(fill = TRUE) + tab <- tab[[2]] nms <- c("x", "qx", "lx", "dx", "Lx", "Tx", "ex", "sex") - tab_m <- setNames(cbind(tab[-1,1:7], 'M'), nms) - tab_f <- setNames(cbind(tab[-1,9:15], 'F'), nms) + tab_m <- setNames(cbind(tab[-1, 1:7], 'M'), nms) + tab_f <- setNames(cbind(tab[-1, 9:15], 'F'), nms) dat <- rbind(tab_m, tab_f) dat <- filter(dat, x != "") # Failed to skip lines when ingesting table dat <- filter(dat, !grepl("Year of Birth", x)) - dat[-8] <- lapply(dat[-8], function (x) {zapsmall(readr::parse_number(x))}) + dat[-8] <- lapply(dat[-8], function(x) { + zapsmall(readr::parse_number(x)) + }) dat$year <- year dat } -years <- seq(1900, 2017, by = 10) -lifetables <- tbl_df(bind_rows(lapply(years, get_lifetables))) %>% +years <- seq(1900, 2100, by = 10) +years <- years[years <= as.numeric(format(Sys.Date(), "%Y"))] +lifetables <- tibble::as_tibble(bind_rows(lapply(years, get_lifetables))) |> arrange(year, sex, x) -readr::write_csv(lifetables[1:nrow(lifetables) %% 100 == 0,], "data-raw/lifetables_sample.csv") -usethis::use_data(lifetables, compress = "xz", overwrite = T) +readr::write_csv( + lifetables[1:nrow(lifetables) %% 100 == 0, ], + "data-raw/lifetables_sample.csv" +) +usethis::use_data(lifetables, compress = "xz", overwrite = TRUE) diff --git a/data-raw/lifetables_sample.csv b/data-raw/lifetables_sample.csv index 729d705..0b28ebe 100644 --- a/data-raw/lifetables_sample.csv +++ b/data-raw/lifetables_sample.csv @@ -1,29 +1,32 @@ x,qx,lx,dx,Lx,Tx,ex,sex,year -99,0.35368,335,119,276,703,2.1,M,1900 -79,0.04954,37833,1874,36895,358165,9.47,F,1900 -59,0.02185,61287,1339,60617,1087067,17.74,M,1910 -39,0.00283,78275,222,78164,3129636,39.98,F,1910 -19,0.00234,85960,201,85860,4504347,52.4,M,1920 -119,0.84276,0,0,0,0,0.68,M,1920 -99,0.3077,2071,637,1752,5078,2.45,F,1920 -79,0.06363,39167,2492,37921,315827,8.06,M,1930 -59,0.00825,82458,680,82118,1968099,23.87,F,1930 -39,0.00282,88661,250,88536,3367067,37.98,M,1940 -19,6.3e-4,94165,59,94135,5774469,61.32,F,1940 -119,0.75314,0,0,0,0,0.81,F,1940 -99,0.29993,1665,499,1415,4268,2.56,M,1950 -79,0.03804,62604,2382,61413,662633,10.58,F,1950 -59,0.009,83535,752,83159,1908996,22.85,M,1960 -39,0.00134,95368,128,95304,4185376,43.89,F,1960 -19,0.00144,96622,139,96553,5732147,59.33,M,1970 -119,0.64653,0,0,0,0,1.01,M,1970 -99,0.22953,6785,1557,6006,22359,3.3,F,1970 -79,0.04222,59032,2492,57786,591426,10.02,M,1980 -59,0.00523,92346,483,92104,2493355,27,F,1980 -39,0.00189,95905,181,95815,4072247,42.46,M,1990 -19,4.1e-4,98731,40,98711,6449890,65.33,F,1990 -119,0.58969,1,1,1,1,1.15,F,1990 -99,0.2325,5259,1223,4648,17487,3.32,M,2000 -79,0.02654,73177,1942,72206,915613,12.51,F,2000 -59,0.00585,91205,533,90938,2359487,25.87,M,2010 -39,0.001,98186,98,98137,4632141,47.18,F,2010 +99,0.30675,1837,563,1555,4420,2.41,F,1900 +79,0.08371,20973,1756,20095,151959,7.25,M,1900 +59,0.01041,70323,732,69957,1627751,23.15,F,1910 +39,0.00415,74877,310,74722,2481797,33.14,M,1910 +19,0.00187,88446,166,88363,5209231,58.9,F,1920 +119,0.84276,0,0,0,0,0.68,F,1920 +99,0.35777,499,178,409,1055,2.12,M,1920 +79,0.04491,55044,2472,53808,535366,9.73,F,1930 +59,0.01477,73866,1091,73320,1492973,20.21,M,1930 +39,0.00153,92371,141,92300,3906546,42.29,F,1940 +19,0.0016,92408,148,92334,5180506,56.06,M,1940 +119,0.75314,0,0,0,0,0.81,M,1940 +99,0.25646,4586,1176,3998,13556,2.96,F,1950 +79,0.05329,49366,2631,48050,438268,8.88,M,1950 +59,0.00616,89982,554,89705,2319661,25.78,F,1960 +39,0.00239,91866,220,91756,3678347,40.04,M,1960 +19,5.3e-4,97556,51,97530,6231523,63.88,F,1970 +119,0.64653,0,0,0,0,1.01,F,1970 +99,0.26923,2861,770,2476,8206,2.87,M,1970 +79,0.03021,69607,2103,68555,820509,11.79,F,1980 +59,0.00749,87856,658,87527,2122000,24.15,M,1980 +39,0.00116,97562,114,97505,4484754,45.97,F,1990 +19,0.00105,98255,103,98203,6015266,61.22,M,1990 +119,0.58969,0,0,0,0,1.15,M,1990 +99,0.19771,10587,2093,9541,40185,3.8,F,2000 +79,0.03691,63919,2359,62740,685165,10.72,M,2000 +59,0.0042,94348,396,94150,2698221,28.6,F,2010 +39,0.00158,96912,153,96836,4251421,43.87,M,2010 +19,3.2e-4,99311,32,99295,6674736,67.21,F,2020 +119,0.52031,5,3,4,7,1.35,F,2020 +99,0.21282,7130,1518,6372,25846,3.62,M,2020 diff --git a/data-raw/names.R b/data-raw/names.R index 7b6e7de..3c435de 100644 --- a/data-raw/names.R +++ b/data-raw/names.R @@ -4,7 +4,11 @@ library(readr) if (!file.exists("data-raw/names")) { tmp <- tempfile(fileext = ".zip") - download.file("https://www.ssa.gov/oact/babynames/names.zip", tmp, quiet = TRUE) + download.file( + "https://www.ssa.gov/oact/babynames/names.zip", + tmp, + quiet = TRUE + ) unzip(tmp, exdir = "data-raw/names") unlink(tmp) } @@ -13,22 +17,30 @@ if (!file.exists("data-raw/names")) { all <- dir("data-raw/names", "\\.txt$", full.names = TRUE) year <- as.numeric(gsub("[^0-9]", "", basename(all))) -data <- lapply(all, read_csv, col_names = FALSE, col_types = list(X2 = col_character())) +data <- lapply( + all, + read_csv, + col_names = FALSE, + col_types = list(X2 = col_character()) +) one <- dplyr::bind_rows(data) names(one) <- c("name", "sex", "n") one$year <- rep(year, vapply(data, nrow, integer(1))) -babynames <- one %>% - tbl_df() %>% - select(year, sex, name, n) %>% - arrange(year, sex, desc(n)) %>% - left_join(applicants, by = c("year", "sex")) %>% - mutate(prop = zapsmall(n / n_all)) %>% - select(-n_all) %>% - arrange(year, sex, desc(n)) %>% +babynames <- one |> + tibble::as_tibble() |> + select(year, sex, name, n) |> + arrange(year, sex, desc(n)) |> + left_join(applicants, by = c("year", "sex")) |> + mutate(prop = zapsmall(n / n_all)) |> + select(-n_all) |> + arrange(year, sex, desc(n)) |> # avoid a data-type change between package versions mutate(n = as.integer(n)) -readr::write_csv(babynames[1:nrow(babynames) %% 1000 == 0 & babynames$n > 1000,], "data-raw/babynames_sample.csv") -usethis::use_data(babynames, compress = "xz", overwrite = T) +readr::write_csv( + babynames[1:nrow(babynames) %% 1000 == 0 & babynames$n > 1000, ], + "data-raw/babynames_sample.csv" +) +usethis::use_data(babynames, compress = "xz", overwrite = TRUE) diff --git a/data/applicants.rda b/data/applicants.rda index 8c50d63..cbf09b2 100644 Binary files a/data/applicants.rda and b/data/applicants.rda differ diff --git a/data/babynames.rda b/data/babynames.rda index 0bfe07c..8083679 100644 Binary files a/data/babynames.rda and b/data/babynames.rda differ diff --git a/data/births.rda b/data/births.rda index b457dc3..6169374 100644 Binary files a/data/births.rda and b/data/births.rda differ diff --git a/data/lifetables.rda b/data/lifetables.rda index 88af1b0..e8369b3 100644 Binary files a/data/lifetables.rda and b/data/lifetables.rda differ diff --git a/tests/testthat/_snaps/data.md b/tests/testthat/_snaps/data.md index 0e2994e..aef9aaf 100644 --- a/tests/testthat/_snaps/data.md +++ b/tests/testthat/_snaps/data.md @@ -7,25 +7,25 @@ year sex n_all 1 1880 F 97605 - 2 1880 M 118400 + 2 1880 M 118399 3 1881 F 98855 - 4 1881 M 108282 - 5 1882 F 115695 + 4 1881 M 108276 + 5 1882 F 115694 6 1882 M 122031 - 7 1883 F 120059 - 8 1883 M 112477 - 9 1884 F 137586 + 7 1883 F 120060 + 8 1883 M 112475 + 9 1884 F 137585 10 1884 M 122738 - 11 2013 F 1923856 - 12 2013 M 2016731 - 13 2014 F 1951652 - 14 2014 M 2044378 - 15 2015 F 1945317 - 16 2015 M 2038331 - 17 2016 F 1928438 - 18 2016 M 2017790 - 19 2017 F 1874899 - 20 2017 M 1963290 + 11 2019 F 1834876 + 12 2019 M 1921774 + 13 2020 F 1767691 + 14 2020 M 1849670 + 15 2021 F 1791567 + 16 2021 M 1873605 + 17 2022 F 1793069 + 18 2022 M 1872977 + 19 2023 F 1749200 + 20 2023 M 1831150 --- @@ -45,16 +45,16 @@ 8 1916 2964000 9 1917 2944000 10 1918 2948000 - 11 2008 4247694 - 12 2009 4130665 - 13 2010 3999386 - 14 2011 3953590 - 15 2012 3952841 - 16 2013 3932181 - 17 2014 3988076 - 18 2015 3978497 - 19 2016 3945875 - 20 2017 3855500 + 11 2013 3932181 + 12 2014 3988076 + 13 2015 3978497 + 14 2016 3945875 + 15 2017 3855500 + 16 2018 3791712 + 17 2019 3747540 + 18 2020 3613647 + 19 2021 3664292 + 20 2022 3667757 --- @@ -63,27 +63,27 @@ Output # A tibble: 20 x 9 x qx lx dx Lx Tx ex sex year - - 1 0 0.146 100000 14596 90026 5151511 51.5 M 1900 - 2 1 0.0328 85404 2803 84003 5061484 59.3 M 1900 - 3 2 0.0163 82601 1350 81926 4977482 60.3 M 1900 - 4 3 0.0105 81251 855 80824 4895556 60.2 M 1900 - 5 4 0.00875 80397 703 80045 4814732 59.9 M 1900 - 6 5 0.00628 79693 501 79443 4734687 59.4 M 1900 - 7 6 0.00462 79193 366 79010 4655244 58.8 M 1900 - 8 7 0.00326 78827 257 78698 4576234 58.0 M 1900 - 9 8 0.00256 78569 201 78469 4497536 57.2 M 1900 - 10 9 0.00203 78368 159 78288 4419068 56.4 M 1900 - 11 110 0.342 487 167 404 1065 2.18 F 2010 - 12 111 0.361 321 116 263 661 2.06 F 2010 - 13 112 0.381 205 78 166 398 1.94 F 2010 - 14 113 0.402 127 51 101 232 1.83 F 2010 - 15 114 0.424 76 32 60 130 1.72 F 2010 - 16 115 0.448 44 20 34 71 1.62 F 2010 - 17 116 0.473 24 11 18 37 1.52 F 2010 - 18 117 0.495 13 6 10 18 1.44 F 2010 - 19 118 0.518 6 3 5 9 1.36 F 2010 - 20 119 0.542 3 2 2 4 1.28 F 2010 + + 1 0 0.120 100000 11969 92047 5828405 58.3 F 1900 + 2 1 0.0306 88031 2694 86683 5736358 65.2 F 1900 + 3 2 0.0149 85336 1270 84701 5649675 66.2 F 1900 + 4 3 0.0101 84066 850 83641 5564974 66.2 F 1900 + 5 4 0.00823 83216 684 82874 5481333 65.9 F 1900 + 6 5 0.00585 82532 483 82290 5398459 65.4 F 1900 + 7 6 0.00428 82049 351 81873 5316168 64.8 F 1900 + 8 7 0.00306 81697 250 81572 5234295 64.1 F 1900 + 9 8 0.00232 81447 189 81353 5152723 63.3 F 1900 + 10 9 0.00186 81258 151 81183 5071371 62.4 F 1900 + 11 110 0.348 225 78 186 490 2.18 M 2020 + 12 111 0.364 147 53 120 304 2.07 M 2020 + 13 112 0.380 93 36 76 184 1.97 M 2020 + 14 113 0.398 58 23 46 108 1.87 M 2020 + 15 114 0.416 35 14 28 62 1.78 M 2020 + 16 115 0.435 20 9 16 34 1.69 M 2020 + 17 116 0.455 12 5 9 18 1.6 M 2020 + 18 117 0.476 6 3 5 9 1.51 M 2020 + 19 118 0.497 3 2 2 5 1.43 M 2020 + 20 119 0.520 2 1 1 2 1.35 M 2020 --- @@ -91,28 +91,28 @@ first_last(lifetables[lifetables$year == 1990, ]) Output # A tibble: 20 x 9 - x qx lx dx Lx Tx ex sex year - - 1 0 0.0103 100000 1028 99108 7890323 78.9 M 1990 - 2 1 0.00075 98972 75 98934 7791215 78.7 M 1990 - 3 2 0.00049 98897 49 98873 7692281 77.8 M 1990 - 4 3 0.00039 98848 38 98829 7593408 76.8 M 1990 - 5 4 0.00031 98810 30 98795 7494579 75.8 M 1990 - 6 5 0.000260 98780 25 98767 7395784 74.9 M 1990 - 7 6 0.00024 98755 23 98743 7297016 73.9 M 1990 - 8 7 0.0002 98731 20 98721 7198273 72.9 M 1990 - 9 8 0.00018 98711 18 98702 7099552 71.9 M 1990 - 10 9 0.000150 98693 15 98686 7000849 70.9 M 1990 - 11 110 0.374 265 99 215 525 1.98 F 1990 - 12 111 0.394 166 65 133 310 1.87 F 1990 - 13 112 0.416 101 42 80 177 1.76 F 1990 - 14 113 0.439 59 26 46 97 1.65 F 1990 - 15 114 0.463 33 15 25 51 1.55 F 1990 - 16 115 0.489 18 9 13 26 1.46 F 1990 - 17 116 0.516 9 5 7 12 1.37 F 1990 - 18 117 0.540 4 2 3 6 1.29 F 1990 - 19 118 0.564 2 1 1 2 1.22 F 1990 - 20 119 0.590 1 1 1 1 1.15 F 1990 + x qx lx dx Lx Tx ex sex year + + 1 0 0.00815 100000 815 99298 8330278 83.3 F 1990 + 2 1 0.00067 99185 66 99152 8230980 83.0 F 1990 + 3 2 0.0004 99119 39 99099 8131828 82.0 F 1990 + 4 3 0.00027 99079 27 99066 8032729 81.1 F 1990 + 5 4 0.00025 99053 25 99040 7933663 80.1 F 1990 + 6 5 0.0002 99028 19 99018 7834622 79.1 F 1990 + 7 6 0.00017 99008 17 99000 7735604 78.1 F 1990 + 8 7 0.00016 98991 16 98983 7636604 77.1 F 1990 + 9 8 0.00014 98975 14 98968 7537621 76.2 F 1990 + 10 9 0.00013 98961 13 98955 7438652 75.2 F 1990 + 11 110 0.396 77 30 61 144 1.88 M 1990 + 12 111 0.414 46 19 37 83 1.79 M 1990 + 13 112 0.432 27 12 21 46 1.7 M 1990 + 14 113 0.452 15 7 12 25 1.61 M 1990 + 15 114 0.472 8 4 6 13 1.53 M 1990 + 16 115 0.494 4 2 3 6 1.44 M 1990 + 17 116 0.516 2 1 2 3 1.37 M 1990 + 18 117 0.540 1 1 1 1 1.29 M 1990 + 19 118 0.564 1 0 0 1 1.22 M 1990 + 20 119 0.590 0 0 0 0 1.15 M 1990 --- @@ -132,16 +132,16 @@ 8 1880 F Alice 1414 0.0145 9 1880 F Bertha 1320 0.0135 10 1880 F Sarah 1288 0.0132 - 11 2017 M Zubeyr 5 0.00000255 - 12 2017 M Zy 5 0.00000255 - 13 2017 M Zyel 5 0.00000255 - 14 2017 M Zyheem 5 0.00000255 - 15 2017 M Zyhier 5 0.00000255 - 16 2017 M Zykai 5 0.00000255 - 17 2017 M Zykeem 5 0.00000255 - 18 2017 M Zylin 5 0.00000255 - 19 2017 M Zylis 5 0.00000255 - 20 2017 M Zyrie 5 0.00000255 + 11 2023 M Zuriah 5 0.00000273 + 12 2023 M Zusha 5 0.00000273 + 13 2023 M Zyaan 5 0.00000273 + 14 2023 M Zyah 5 0.00000273 + 15 2023 M Zyamir 5 0.00000273 + 16 2023 M Zyell 5 0.00000273 + 17 2023 M Zyen 5 0.00000273 + 18 2023 M Zymirr 5 0.00000273 + 19 2023 M Zyquan 5 0.00000273 + 20 2023 M Zyrin 5 0.00000273 --- @@ -151,16 +151,16 @@ # A tibble: 20 x 5 year sex name n prop - 1 1990 F Jessica 46475 0.0226 - 2 1990 F Ashley 45558 0.0222 - 3 1990 F Brittany 36538 0.0178 - 4 1990 F Amanda 34408 0.0168 - 5 1990 F Samantha 25866 0.0126 - 6 1990 F Sarah 25816 0.0126 - 7 1990 F Stephanie 24861 0.0121 - 8 1990 F Jennifer 22226 0.0108 - 9 1990 F Elizabeth 20744 0.0101 - 10 1990 F Lauren 20500 0.00998 + 1 1990 F Jessica 46480 0.0226 + 2 1990 F Ashley 45559 0.0222 + 3 1990 F Brittany 36536 0.0178 + 4 1990 F Amanda 34413 0.0168 + 5 1990 F Samantha 25868 0.0126 + 6 1990 F Sarah 25825 0.0126 + 7 1990 F Stephanie 24864 0.0121 + 8 1990 F Jennifer 22235 0.0108 + 9 1990 F Elizabeth 20748 0.0101 + 10 1990 F Lauren 20507 0.00998 11 1990 M Zan 5 0.00000232 12 1990 M Zander 5 0.00000232 13 1990 M Zedekiah 5 0.00000232