class: center, middle, inverse, title-slide .title[ # Misc Topics / Parting Thoughts ] .subtitle[ ## STAT 7500 ] .author[ ### Katie Fitzgerald ] --- layout: true <div class="my-footer"> <span> <a href="https://kgfitzgerald.github.io/stat-7500" target="_blank">kgfitzgerald.github.io/stat-7500</a> </span> </div> --- # Let's recap / reflect + What's something you can do now that you couldn't do before this class? -- + Is there a way in which you *think* differently than you did at the beginning of this class? (e.g. "habits of mind", ways of approaching problems, data ethics considerations, other?) --- # What package do I need? --- # What function do I need? [STAT 7500 Communal Cheat Sheet](https://docs.google.com/document/d/1K3Anyz4Qq79xUBjIkzSlQhjisbhu6cIPY-GMSp_zcq0/edit?usp=sharing) + Make a list of every function used + Provide brief definition of what it's used for + Look at slides, in-class .qmds, homework --- class: middle # Additional programming tools & resources --- # Additional programming tasks + functions + for loops / iteration + simulations, random variables & distributions + statistical inference - base R, infer + modeling + visualization + Interactive Web apps / dashboards --- # Writing Functions Useful when you find yourself thinking: + "I'm repeating the same code over and over" + "Only one part keeps changing" + "If I make one improvement, I wish it applied everywhere" -- ``` r plot_histogram <- function(data, var) { ggplot(data, aes(x = .data[[var]])) + geom_histogram(bins = 30, color = "white") + labs(title = paste("Histogram of", var), x = var, y = "Count") + theme_minimal() } plot_histogram(penguins, "bill_length_mm") ``` --- # Writing Functions: Use cases + Create a histogram for every numeric variable + Produce a summary table for each STEM course + Write out a csv file of respondents for every professor/class + Other? --- # Writing Functions: Your Turn How could this be turned into a function? ``` r (a - min(a, na.rm = TRUE)) / (max(a, na.rm = TRUE) - min(a, na.rm = TRUE)) (b - min(b, na.rm = TRUE)) / (max(b, na.rm = TRUE) - min(b, na.rm = TRUE)) (c - min(c, na.rm = TRUE)) / (max(c, na.rm = TRUE) - min(c, na.rm = TRUE)) (d - min(d, na.rm = TRUE)) / (max(d, na.rm = TRUE) - min(d, na.rm = TRUE)) ``` --- # Iteration / for loops / `purrr` .pull-left[ "Do this iteratively, for every element" + Already learned some powerful tools that perform the same action on multiple things: + `facet_wrap` + `group_by` plus `summarize` + To do something to multiple columns, use `across()` ] -- .pull-right[ ``` r df |> summarize( n = n(), a = median(a), b = median(b), c = median(c), d = median(d), ) df |> summarize( n = n(), across(a:d, median), ) ``` ] --- # For loops ``` r squares <- numeric(5) # create an empty numeric vector of length 5 for (i in 1:5) { squares[i] <- i^2 } squares ``` ``` ## [1] 1 4 9 16 25 ``` -- BUT, R is vectorized, so it's quicker to just do ``` r x <- 1:5 squares <- x^2 squares ``` ``` ## [1] 1 4 9 16 25 ``` --- # Iteration with `apply` family ``` r #lapply over a list l <- list(a = 1:5, b = 6:10) lapply(l, sum) ``` ``` ## $a ## [1] 15 ## ## $b ## [1] 40 ``` ``` r # sapply returns a vector/matrix sapply(l, sum) ``` ``` ## a b ## 15 40 ``` --- # Iteration with `purrr` package (`tidyverse`) ``` r nums <- list(1:5, 6:10) map_dbl(nums, sum) ``` ``` ## [1] 15 40 ``` Use case: reading in a bunch of data files ``` r grade_files <- paste("./raw data/", dir(path = "./raw data/", pattern = "grade", ignore.case = TRUE), sep = "") grades <- grade_files %>% map_dfr(read_excel, sheet = 2) %>% clean_names() %>% filter(term == 2237) ``` --- ### Simulations / Random variables & Distributions Why simulate? + helps us understand randomness / sampling variability + allows us to tackle questions we can't solve analytically + allow us to test methods / estimators (is this unbiased? which one has smaller variance?) + allows us to model / forecast potential outcomes, possible futures (e.g. in finance, public health, environmental risk) --- ### Simulations / Random variables & Distributions + `rnorm()`, `rpois()`, etc - generate random variables from a distribution + `sample()` - take a random sample of observations, with or without replacement + `sample_n()` to take random sample of rows in dplyr pipeline + `replicate()` - concise way to repeat simulations ``` r replicate(1000, mean(rnorm(50))) ``` ``` ## [1] -0.4530530118 0.1395295269 0.0199780863 0.0625082735 ## [5] 0.2106426950 0.0985646492 0.0069353764 -0.0231456489 ## [9] -0.1162604290 0.0726886885 0.0085940128 -0.2823480243 ## [13] -0.0028933295 -0.1728302632 0.0720542674 -0.0737286527 ## [17] -0.0404575689 0.0767064398 -0.2165062441 0.0810771364 ## [21] -0.1890234193 0.0206194666 0.0485567969 -0.0636407108 ## [25] 0.1812670059 0.0859991394 0.0273992081 0.1440828634 ## [29] 0.0470098646 0.0145227323 -0.0470201802 -0.0950733163 ## [33] -0.0915209639 -0.3573048527 0.0363716221 0.2938463793 ## [37] -0.0159553360 0.2743145626 -0.0159498294 -0.0083361830 ## [41] -0.1021715380 0.2138442213 -0.1081976456 0.1028142885 ## [45] 0.0020568915 0.1807966234 0.1304437508 0.0263048263 ## [49] -0.0039085270 0.0667218852 -0.2250734261 -0.0292935806 ## [53] 0.0787625725 0.0576983539 -0.0166010348 0.0321359707 ## [57] 0.0147638864 0.0698534152 -0.0503422243 0.1384141887 ## [61] 0.1679589696 -0.0102606206 0.0700724793 -0.0502241934 ## [65] 0.0113454010 0.1823714625 0.0117760208 -0.0077275569 ## [69] 0.0080958999 0.0830673596 -0.3491423613 -0.0124239702 ## [73] 0.0416819673 -0.0441526373 -0.1572483540 -0.0495177658 ## [77] 0.0532337130 -0.0183266826 -0.1024147874 -0.0203777992 ## [81] -0.0508672815 0.2044608467 0.0981939104 0.1918536573 ## [85] -0.2914525154 -0.0725003191 0.0056782762 0.0926574945 ## [89] 0.1727761198 -0.1318131800 -0.0674179616 -0.0061270501 ## [93] -0.1931730177 -0.0094611113 -0.3150199341 -0.0109651965 ## [97] -0.1524454516 -0.0806038305 -0.0499161237 -0.1143572236 ## [101] -0.0878075896 0.2094697729 0.1904999325 -0.2572743083 ## [105] -0.0472598370 0.2825545149 0.1586638212 0.0672369454 ## [109] -0.0431534231 0.0430930125 0.0909538841 -0.0102941097 ## [113] 0.1597073453 0.0845245031 -0.2263401841 0.1909852825 ## [117] 0.3814810725 0.1089023594 -0.0890631251 -0.2969048922 ## [121] -0.0434907225 0.1244259357 -0.0028974077 -0.0007949131 ## [125] 0.0892800344 -0.1640893606 0.0333376190 -0.0497143985 ## [129] -0.1953124875 -0.1628674891 0.1950287993 -0.0780342306 ## [133] 0.1685687676 -0.1460024765 -0.1161362900 0.0702661462 ## [137] 0.0186170482 0.1266633674 0.0181207052 -0.0084820140 ## [141] 0.0785142848 0.0888194207 0.1286050197 0.0752029972 ## [145] 0.1185669186 0.1368261486 -0.0855066185 0.0890087620 ## [149] 0.1008232737 -0.0960146977 -0.0799971557 -0.0126690172 ## [153] 0.0115135742 -0.0964818542 0.1185946075 0.1019246900 ## [157] 0.0063922706 0.0410826610 0.0162429769 0.1803619247 ## [161] 0.0131780804 0.1109517153 0.0901698885 -0.0329471607 ## [165] 0.1655755381 -0.0038245382 0.0768488597 -0.0617750759 ## [169] 0.1767936968 0.0784920832 0.0696128729 0.2521678005 ## [173] -0.2229849929 -0.1727534752 0.2061128281 -0.1697291391 ## [177] -0.0268486140 -0.1140835797 0.0488798808 0.1023177714 ## [181] -0.0535474042 0.0021669022 0.0144538152 0.1023333752 ## [185] -0.0056518802 0.2988106854 0.0830383238 0.2393185084 ## [189] -0.0998570290 0.1076092570 -0.0673383318 -0.0059902141 ## [193] -0.2138384650 -0.1663204076 -0.2489211725 0.1493489410 ## [197] -0.0217061747 -0.3130915834 -0.1594487143 -0.0771464539 ## [201] -0.0736189515 -0.1581415942 -0.0786631611 0.2493188251 ## [205] -0.0251725760 0.1886227063 -0.0635200507 -0.0108543815 ## [209] -0.1897300311 0.2167787770 0.1508843777 -0.0174764213 ## [213] 0.1357981044 0.0369178288 -0.1454943424 0.0678101712 ## [217] -0.2075498850 0.2114005186 0.1379469828 -0.1563613166 ## [221] -0.0333510998 0.1301088776 -0.0236480884 0.0621539839 ## [225] 0.2846746239 0.1759548546 -0.0103459215 0.2319536363 ## [229] 0.0057335255 -0.1313415020 0.0936036369 -0.1062063273 ## [233] 0.2050776506 -0.2856991001 0.0584877509 0.1741047705 ## [237] -0.1767291504 0.1057744383 0.1565625418 -0.0238452174 ## [241] -0.0444750626 -0.1416106019 0.0202681432 -0.1326060268 ## [245] -0.0329374442 0.0623183574 -0.1636932950 0.0020654945 ## [249] 0.0783456967 0.0423485628 0.0133791707 -0.1448055746 ## [253] 0.0841996421 0.0035444560 0.0253592432 -0.1806638270 ## [257] 0.1209247446 0.2800201208 0.1563100329 -0.0972409425 ## [261] -0.2104122541 -0.0198493029 -0.2561808079 -0.4368175047 ## [265] -0.0080453054 -0.0200557055 -0.1580201300 0.0912105929 ## [269] -0.0174100071 0.1169070899 0.2704856407 0.0876446292 ## [273] -0.0656386575 0.0530577474 -0.0660762613 0.1676169323 ## [277] 0.1802895203 -0.0144861961 -0.0874305769 -0.0869132350 ## [281] 0.0584608088 -0.0928337883 -0.0105544502 -0.0908662583 ## [285] 0.0926653166 0.0118216420 -0.0703809278 0.0685391786 ## [289] -0.0857177960 0.4768139428 -0.1887351543 -0.2313718410 ## [293] 0.0534345253 -0.0544703764 -0.1403124129 -0.3120507141 ## [297] 0.0987912669 -0.2550400130 0.2192488449 0.2389757120 ## [301] -0.2111151297 -0.0010934968 -0.1811805223 -0.0728197783 ## [305] -0.1453026339 0.1940379955 -0.2618620270 0.0341248748 ## [309] 0.1153477646 0.0313274450 -0.1909098589 -0.2366555259 ## [313] -0.0159161718 -0.0687827124 -0.0297240284 0.1055818146 ## [317] -0.0069137848 -0.0409290460 -0.1995118041 0.0756988455 ## [321] -0.1996361546 -0.0994785624 0.2047698974 0.0773988667 ## [325] -0.0288919364 0.0985584096 -0.1167985717 -0.0087135515 ## [329] 0.0178055660 -0.3130365852 -0.3286579706 0.0704318021 ## [333] 0.0590843984 -0.2123521541 0.0197323363 -0.0431769346 ## [337] -0.1512767914 0.2734609017 -0.4042295412 0.0336396354 ## [341] -0.1148498692 0.1355682917 0.0533022911 -0.0644153268 ## [345] -0.0296226364 0.1752659415 0.0501264163 0.0888036796 ## [349] -0.0368280957 0.0773353803 -0.1569759908 0.1247681445 ## [353] -0.1854082298 0.0616597357 0.0153739129 0.0041959817 ## [357] 0.0891817331 -0.3039013993 0.1313061821 0.2074592042 ## [361] -0.1723578211 -0.0498776598 -0.0821419229 0.1412300734 ## [365] -0.1946509967 0.0124229256 -0.1785600776 -0.0130845514 ## [369] 0.1195982724 0.0679714648 -0.0039543509 -0.0221405055 ## [373] -0.2814274893 0.0304058825 0.1590616033 -0.0763383506 ## [377] 0.2831554173 0.1515201170 -0.1388110358 0.0083714421 ## [381] 0.0887135980 -0.2380257037 0.1027647966 0.1648607457 ## [385] -0.1633570630 0.0526183897 0.0893050011 -0.0301094232 ## [389] -0.1457437026 0.1302157582 -0.0658520406 0.0285202763 ## [393] 0.0135812095 0.0329018041 0.2148853863 -0.1086852883 ## [397] 0.0721136748 -0.1174556859 0.0860518497 -0.1007452261 ## [401] -0.1052734707 0.0631733435 -0.1729043327 -0.0672108711 ## [405] 0.2097364144 -0.0416359494 -0.2951127917 0.0273821292 ## [409] -0.1105265311 0.0277697193 0.0467502895 0.0790820705 ## [413] -0.1583812421 -0.0064987468 -0.0481809617 -0.0627135785 ## [417] -0.0371813609 0.3003298459 -0.0430514788 0.0827642544 ## [421] 0.1608622608 -0.1539324672 0.2580113431 0.1546260459 ## [425] 0.1459579449 0.1302631876 -0.1169813365 0.1512836369 ## [429] 0.0079678917 0.1963701328 -0.0142220112 -0.2635456995 ## [433] 0.0127784386 0.1085032362 0.1072412948 0.0425942476 ## [437] 0.0531120758 0.2521531019 0.0925756404 -0.3684554699 ## [441] -0.2393463346 0.1706430588 0.1984811092 0.0619103412 ## [445] -0.1285355506 0.0482193798 0.1352265718 -0.3313740885 ## [449] 0.0455459770 0.2844761300 0.2524153927 0.0079150021 ## [453] -0.0819146588 -0.0537570341 -0.1363850237 0.0331619143 ## [457] 0.1422854760 0.0966894942 0.0332374123 -0.1100387118 ## [461] -0.0727684059 0.0947675216 0.1063688353 -0.2458777285 ## [465] -0.0195340938 -0.0455140013 0.0014217216 -0.2216776808 ## [469] -0.2468577695 -0.1301166451 0.1802193114 -0.1689350687 ## [473] -0.0821072999 -0.2556197658 0.0527025676 0.0241972144 ## [477] 0.0206168494 -0.1770460310 0.0011707542 0.0216625112 ## [481] -0.0282831357 -0.1739518314 -0.0673245959 0.4076067578 ## [485] 0.0631828020 -0.0829420692 -0.0120500546 -0.0053578985 ## [489] -0.2215032142 0.2647683334 -0.0194455452 -0.1154978877 ## [493] -0.0699396073 0.1459017150 -0.1332809940 0.1480812385 ## [497] 0.1374465487 -0.0832103472 0.0648445060 -0.2142189580 ## [501] 0.1264735958 0.0002697708 -0.1275987159 -0.0025047478 ## [505] 0.0032223206 -0.0120830334 -0.0391386223 0.0601628704 ## [509] -0.0814156786 0.1080341154 -0.1165887715 -0.1366849471 ## [513] 0.0702155523 -0.0107554180 -0.0298803338 -0.2650954129 ## [517] 0.0653895317 0.1581040640 -0.0102920296 0.0542371818 ## [521] 0.1668561437 -0.0947613776 -0.0049569964 -0.0416744985 ## [525] -0.1530704909 0.1477877271 -0.0882277952 -0.1162501846 ## [529] -0.0460255339 0.2530803142 0.3231798976 -0.1741486554 ## [533] 0.0604143960 0.0252520495 0.0301807232 0.1019379042 ## [537] -0.2018329648 -0.1234838701 0.1155731329 0.0947018002 ## [541] -0.4182365878 0.0193189415 -0.0464631064 -0.0197703565 ## [545] 0.0980766664 0.0428367184 0.1970440600 -0.2010939330 ## [549] -0.0634239537 0.1807007379 0.1937386144 -0.1168874977 ## [553] -0.3025761176 -0.0596290067 -0.0298921220 0.2282583167 ## [557] 0.1114197427 0.0226222397 -0.0060638795 0.0062442786 ## [561] -0.0865549322 0.2108728440 0.0853612282 -0.0691921703 ## [565] 0.0078512228 -0.0171677143 -0.0662676183 -0.0049941821 ## [569] -0.0653585975 -0.0067789185 0.0075146540 0.0990716352 ## [573] 0.0400006003 -0.0548007956 -0.0112223312 0.2356272652 ## [577] -0.0280396139 -0.2915518351 -0.0610009648 -0.1194808930 ## [581] 0.0856599036 -0.1526101396 -0.1081516397 -0.0402010876 ## [585] -0.0733557784 0.0265017698 -0.0065330133 0.3175141554 ## [589] -0.0163139235 0.0740932505 0.1879234274 -0.1107429753 ## [593] 0.2623754153 -0.0616944171 0.1355763924 0.0121800045 ## [597] 0.1798766669 0.0485147683 0.3405488154 0.0710978216 ## [601] -0.0689239427 -0.0896333823 0.0712421993 -0.0137312355 ## [605] -0.1050345975 0.0107199301 0.0944045282 -0.1781855554 ## [609] -0.1099747339 0.0928110546 0.1707720577 -0.1898193347 ## [613] 0.0962178480 0.0107254152 -0.1568266668 0.0323225058 ## [617] 0.0597099836 -0.1115623521 0.0111085429 0.0082794502 ## [621] 0.0678611059 0.1352703542 -0.0623973652 0.1455917829 ## [625] -0.0765043604 0.1466030323 0.0336673534 0.1227735584 ## [629] -0.0015275951 -0.0260332514 0.0079771026 -0.0203800021 ## [633] 0.5320841723 0.0304642360 -0.2301389099 0.1585952545 ## [637] -0.0401373012 0.0504433917 0.1548000100 0.1099248110 ## [641] 0.0083399841 0.2173740737 0.0338820246 0.0779434063 ## [645] 0.0284056853 -0.1372912667 -0.0201156128 -0.1938332492 ## [649] -0.0129608269 -0.0324710609 0.1100465234 -0.0210040420 ## [653] 0.2506386537 -0.2122212824 -0.0952805011 0.1913447999 ## [657] -0.1392207948 -0.0146708524 -0.0168700937 -0.2064675529 ## [661] -0.1911605094 0.1279817506 0.2284319092 -0.2569554664 ## [665] 0.0923241598 -0.0406293434 -0.1927044919 0.2640813458 ## [669] 0.0445445260 -0.1722400779 0.1098802247 0.1214758589 ## [673] 0.3167310155 0.0806478088 0.0615370148 0.1943056883 ## [677] -0.0075270394 -0.1658871022 -0.0610335802 -0.1758435646 ## [681] -0.0802374170 0.0157517635 -0.0543053824 0.0241953916 ## [685] -0.0746110544 -0.1926607028 0.1620062553 -0.2190535095 ## [689] 0.3072006250 0.0435183034 0.3739596660 0.3094631316 ## [693] 0.2071615473 -0.0002865373 -0.0309689184 -0.0556711197 ## [697] -0.1183614959 0.1108164019 -0.0767750643 -0.0079900931 ## [701] -0.0367443367 0.0034421375 -0.0436539745 0.1694900635 ## [705] 0.2070724430 -0.2004166251 0.0872736550 -0.0477785413 ## [709] 0.2116444628 0.4382235636 0.0563426739 -0.0298769406 ## [713] -0.3287662807 0.1344052524 -0.0480596029 0.2597426162 ## [717] -0.1463074707 -0.2825593691 -0.1806134085 -0.0423120258 ## [721] -0.0073987168 -0.0981975599 -0.1100933883 -0.0662395401 ## [725] -0.1744856494 0.0112710370 -0.2266172732 0.0100824576 ## [729] -0.0962132986 -0.2650525451 0.2045361126 -0.0080140505 ## [733] -0.0006771766 0.1871907416 0.2360524609 -0.0948583103 ## [737] -0.0375468989 0.0490566077 -0.0559635303 -0.0504224542 ## [741] -0.1807224359 -0.2152380024 0.1496037559 0.0674846807 ## [745] -0.2065159042 -0.2432808712 0.2699787675 -0.2531570583 ## [749] -0.0399239223 0.0977414118 -0.0151821087 -0.1937518180 ## [753] 0.0498134322 -0.0227670841 -0.0235006966 0.0103598367 ## [757] 0.0702792262 -0.1171992870 -0.1206288188 0.4090832299 ## [761] -0.0164711348 0.1345749337 0.1015748414 -0.0518974792 ## [765] 0.1151772772 -0.1111471890 0.2986849972 -0.0434919681 ## [769] -0.1434838802 -0.1701476778 0.0489272141 -0.0386016190 ## [773] -0.0479239131 -0.0276725353 0.2417120824 0.1176180948 ## [777] 0.0842730756 0.0329429065 -0.2509362335 0.1894930528 ## [781] 0.0282908386 -0.0934989501 0.1475567446 0.1663706512 ## [785] 0.1693386127 0.0461492659 -0.4327692289 0.1369498899 ## [789] -0.0309989678 0.2129975594 0.0973832519 -0.0181180164 ## [793] 0.0502199309 0.0753705898 0.0662990085 0.0422728175 ## [797] -0.0242008495 0.0720526515 0.2410667853 -0.0054761419 ## [801] -0.2234157627 0.2160148245 0.0310662646 -0.2096063365 ## [805] 0.0305955060 -0.0268737534 -0.0160234781 0.0510880175 ## [809] 0.0377118615 -0.1006778877 -0.1431326362 0.0822324591 ## [813] -0.1796435905 0.1281718214 -0.0544280963 0.0316530462 ## [817] 0.1746210283 0.1945332875 0.3100684738 -0.2567358628 ## [821] 0.2748651652 -0.0335200185 0.0815045602 -0.1908176440 ## [825] 0.0536962304 -0.0947579896 -0.2204652436 0.1663194134 ## [829] 0.2942769982 0.0112962575 -0.0227428850 -0.0591494712 ## [833] 0.0489018351 -0.0417566203 0.2094443600 -0.0793291012 ## [837] 0.2704754151 -0.0362893220 0.2522765629 -0.0275371856 ## [841] -0.2548696618 -0.1651008297 -0.1112071496 0.0413000227 ## [845] -0.0512160082 0.0957934642 0.0432806219 -0.0578565326 ## [849] -0.0623293927 -0.1092114781 0.0929250656 -0.2266880949 ## [853] 0.0718973776 -0.2187195972 -0.0784752867 0.1190365418 ## [857] -0.0561386706 -0.0795691720 -0.0272102826 -0.2588902706 ## [861] -0.0130496434 0.0149871797 -0.0550017790 0.1045063707 ## [865] 0.1606632047 -0.1671216761 -0.1725723532 0.0607078802 ## [869] -0.1255807663 -0.0482403849 0.2873636431 0.3154579598 ## [873] 0.2273217559 -0.0540619284 -0.0602291576 0.0805036892 ## [877] 0.1882591942 0.0173156662 0.0670465314 -0.0311822419 ## [881] 0.0953539513 -0.0122040949 0.1666757657 0.2115316479 ## [885] 0.2870853149 0.0482284734 -0.1063048444 -0.0267086648 ## [889] 0.0093477373 0.0015507748 0.0312006555 0.0069575984 ## [893] -0.0970929662 0.0492110862 -0.1068268348 -0.0315423913 ## [897] 0.1933298587 -0.2524430554 0.1743004341 -0.0589798236 ## [901] 0.2109656507 -0.2564687870 -0.1818637255 0.1896960739 ## [905] -0.0942897309 -0.0328501919 0.1328728481 0.0734448881 ## [909] 0.0383204584 -0.1946087872 0.0213498652 0.0066916121 ## [913] -0.0835167150 -0.0198344639 -0.0156627209 -0.0675433574 ## [917] -0.0648126839 0.1239247088 -0.1888173504 0.2580783832 ## [921] -0.0068793151 0.1408644985 -0.1290955597 0.0154894935 ## [925] -0.0623499687 0.0343536576 -0.3012685543 -0.1774328013 ## [929] -0.0209333056 -0.0535589682 0.1890204590 -0.0597798276 ## [933] 0.1506775040 -0.2016267534 0.1373954617 -0.0189893517 ## [937] 0.0079136811 0.0322484203 -0.0739261342 -0.0818399607 ## [941] -0.0890519133 -0.2058461521 -0.1726764023 0.0485219280 ## [945] -0.0619634386 0.1273066727 0.1082294127 -0.1220004429 ## [949] -0.2414354223 0.0306799041 -0.1082482272 -0.0328394937 ## [953] -0.2299437679 -0.0489613248 -0.2412295376 0.3800781660 ## [957] -0.1103323971 0.3161747448 -0.1378150860 0.0169428799 ## [961] 0.1169779138 0.1045207932 0.0629728912 -0.1491275441 ## [965] 0.0299864381 0.1053715009 0.0047787519 0.0996481448 ## [969] 0.0604812179 0.1299682921 -0.0369038969 -0.0428528525 ## [973] -0.1558868410 -0.0578221256 0.0049189499 -0.1774683220 ## [977] -0.0681718263 -0.0382033213 -0.2396747659 -0.0567006853 ## [981] -0.1992389459 0.2298437524 -0.0706117765 0.1184521476 ## [985] 0.0359558591 -0.0539682401 0.2276079331 -0.0002164068 ## [989] 0.3185146936 0.0372514043 -0.0721187604 0.0632671126 ## [993] 0.1477160092 0.0380733661 -0.3510386344 -0.1715834059 ## [997] 0.0408252303 -0.1184924395 -0.1013848940 0.0161379168 ``` --- ``` r sims <- data.frame(xbar = replicate(1000, mean(rnorm(50)))) ggplot(sims, aes(x = xbar)) + geom_histogram(color = "white") ``` <img src="09-parting-thoughts_files/figure-html/unnamed-chunk-11-1.png" width="60%" style="display: block; margin: auto;" /> --- # Statistical inference in R + `t.test()`, `prop.test()`, `chisq.test()`, `anova()` + `infer` package - tidyverse friendly --- # Modeling in R + `lm` for basic linear models + `glm` for generalized linear models (e.g. logistic) + `summary()` - for coefficients / model output + `predict()` - predictions for any fitted model + `broom` package for tidying model output + `tidy()`, `glance()`, `augment()` + `lme4` package for mixed-effects models + `survival` package for survival models + `tidymodels` package - modeling & machine learning workflows --- # Upping your visualization game + [Themes to spice up visualizations with `ggplot2`](https://towardsdatascience.com/themes-to-spice-up-visualizations-with-ggplot2-3e275038dafa/) -- + Combine plots: [cowplot](https://cran.r-project.org/web/packages/cowplot/vignettes/introduction.html) & [patchwork](https://patchwork.data-imaginist.com) -- + [Fundamentals of Data Visualization book](https://clauswilke.com/dataviz/index.html) -- + [The R Graph Gallery](https://r-graph-gallery.com) -- + [Color blindness simulator](https://www.color-blindness.com/coblis-color-blindness-simulator/#google_vignette) -- + [The Science of Visual Data Communication: What Works](https://faculty.sites.iastate.edu/tesfatsi/archive/tesfatsi/ScienceOfVisualDataCommunication.FranconeriEtAl2021.pdf) -- + Take my data viz course next year :) --- # Interactive Web Apps / Dashboards [Shiny](https://shiny.posit.co) + My use cases: + [MLB Player's WAR stats](https://kgfitzgerald.github.io/baylor_apu_score/baseball/mlb_prime_age/) + [Z-scores](https://kgfitz.shinyapps.io/zscores/) + [Calculate your final grade](https://kgfitz.shinyapps.io/calculate_final_grade/) + Dashboard of enrollment trends + [Shiny Gallery](https://shiny.posit.co/r/gallery/) --- ### Quarto / RStudio Infrastructure: what else can it do? + Slides + [Quarto website](https://quarto.org/docs/presentations/) + [Github repo](https://github.com/kgfitzgerald/stat-7500) for our [course website](https://kgfitzgerald.github.io/stat-7500/) + [Xaringan presentations](https://bookdown.org/yihui/rmarkdown/xaringan.html) (R Markdown) -- + Websites + Our course website - [Just the Docs template](https://github.com/just-the-docs/just-the-docs) + [Personal website](https://katie-fitzgerald.netlify.app) + [MATH 250: Data Analysis](https://apumath250.netlify.app) -- + Books + [Intro to Stats and Data Science](https://nustat.github.io/intro-stat-ds/) + See [Quarto Gallery](https://quarto.org/docs/gallery/) --- # Github + [GitHub](https://github.com) - storing, sharing, collaborating on code + [Happy Git and GitHub for the useR](https://happygitwithr.com) + Clone people's repositories and see how they code / build things! + Build a public presence on GitHub --- # Communities to join + [American Statistical Association](https://www.amstat.org/membership/become-a-member/membership-options) (~$30 student membership) + [R Ladies](https://www.rladiesphilly.org) --- # Statistics for social good resources + [Data4SDGs](https://www.data4sdgs.org) + [HRDAG](https://hrdag.org) + [Statistics Without Borders](https://www.statisticswithoutborders.org) + [DataKind](https://www.datakind.org) + [Health of Federal Statistical Agencies / Nation's Data is at Risk](https://www.amstat.org/policy-and-advocacy/assessing-the-health-of-the-principal-federal-statistical-agencies) --- # Suggested reading + [Communicating with data: The Art of Writing for Data Science](https://communicating-with-data.github.io) + [Bernoulli's Fallacy: Statistical Illogic and the Crisis of Modern Science](https://cup.columbia.edu/book/bernoullis-fallacy/9780231199957/) + [How Data Happened: A History from the Age of Reason to the Age of Algorithms](https://www.amazon.com/How-Data-Happened-History-Algorithms/dp/1324006730) + [Race after technology: Abolitionist Tools for the New Jim Code](https://www.amazon.com/Race-After-Technology-Abolitionist-Tools/dp/1509526404/ref=sr_1_1?crid=27KPV1IGM64XT&dib=eyJ2IjoiMSJ9.X9ombf3wyAE9d7vCaXniRAzEZZ8Q7-hjrC0Z7LCIExhsbGb-m8JqB8Kq7hiUM7INbPV3y3LT9RJezP7C4jHeSFDxW-CZHVdeA0JlVJwu446VNHsJOjYM0-Z8MYFB6QVD1KFg_6JYTCwUoOb9S85kGyNFBEa5wKubwiJ0VLvhDJ903H-OEIRfrxzepVYBCqyD1oVV0vkuZIR-msjRY2hHEA.RP9Hh9EpRRR7unLea4UiVQqPOVHhya7xnuxCcyWa5x8&dib_tag=se&keywords=race+after+technology&qid=1765394654&sprefix=race+after+tech%2Caps%2C117&sr=8-1) + [Automating Inequality: How High-Tech Tools Profile, Police, and Punish the Poor](https://www.amazon.com/Automating-Inequality-High-Tech-Profile-Police/dp/1250215781/ref=sr_1_1?crid=3TFDSG3BLH17J&dib=eyJ2IjoiMSJ9.LPoZC9frqeR5DSJFh2QBLAasy_6p3a_TEcMvWpeHmrsnBB5gSVaf2vj8OtihIHdIk4dbLJyH5doSdTSNZaPe7xPeH_7gT1CWsD71qSNweFUm9ghdtP-770ZhyuCEsdQw0renJPbLeglglgrwh8s20w.taOIpS93Nvy6PRFiLbx_lyAfZcxq3PxTbHMMc0UoeWA&dib_tag=se&keywords=automating+inequality&qid=1765394681&sprefix=automating+inequality%2Caps%2C114&sr=8-1) + [Invisible Women: Data Bias in a World Designed for Men](https://www.amazon.com/Invisible-Women-Data-World-Designed/dp/1419735217/ref=sr_1_1?crid=RSXPKTJBQF6K&dib=eyJ2IjoiMSJ9.boV-evutYwZevi0ZYJWYZyg3JsnXcZU-0rwqBHh9TTVihBqrQKXINYrqOtABPFRGwtEGVrH5STZvdbSGeKxLTdm3D2nedokivo7tN9swxCE7vQUJ_QQ0i4Fo8krUr8hsot-v8jjHm3C3rZhXr_yLPE1EhZVzuoUqbmj7kq6d95YOrX3jY6mfSHuXbVKAnPusy-ZEcc2rIRBwMdD6jeQQnQ0AO-JrkkB6b8BBe5Z5sfI.nwPOn69smpNYZlUYnsALebUoq_DlAiSdxMhdaod8rtE&dib_tag=se&keywords=invisible+women&qid=1765394713&sprefix=invisible+women%2Caps%2C135&sr=8-1) + [Mathematics for Human Flourishing](https://www.amazon.com/Mathematics-Human-Flourishing-Francis/dp/0300258518/ref=sr_1_1?crid=1QVCE98335WL&dib=eyJ2IjoiMSJ9.ZKJG4AtPX51kQ2BqN9c3Fl9CqYm2n7PfBoCdJ3E1VPI.cYdtlRDZUvpTKDjJug3w2C8n3Rupj0qE9sTEYW7grso&dib_tag=se&keywords=mathematics+for+human+flourishing+by+francis+su&qid=1765394733&sprefix=mathematics+for+hum%2Caps%2C131&sr=8-1) + [The Book of Why: The New Science of Cause and Effect](https://www.amazon.com/Book-Why-Science-Cause-Effect/dp/1541698967/ref=sr_1_1?crid=38721B91XRHZA&dib=eyJ2IjoiMSJ9.77Kcrbw5e-DGGNNcwPR_yzl30Z2ehwG3XR2OGxrxDvD8z8k5PaL9bysdJ2ySXagI9urFzTigt8FAUhF9K0rIRS6LgI6NNtBiB1xEqX_q4Ujxre-M7zTtuZCp3yBM9n_d5_4bh64SVKvvE1E6AodA87CjckaSIu_0v5Aijp3dWgdQ33phbJ9lSACeJAGJXK1FiZTfl44PTCEz4aKDWXKTJ7ucMp5zru8Arm827ClbZCQ.Iq8uipo4x3PzTYB4eWvyyTKehDRAR_yoSGunny6Mhz4&dib_tag=se&keywords=the+book+of+why&qid=1765394750&sprefix=the+book+of+why%2Caps%2C117&sr=8-1) + [The Lady Tasting Tea: How Statistics Revolutionized Science in the Twentieth Century](https://www.amazon.com/Lady-Tasting-Tea-Statistics-Revolutionized/dp/0805071342/ref=sr_1_1?crid=DXPTU7TMPAAP&dib=eyJ2IjoiMSJ9.avHxPviBBZwwDThTorkSU237idVigC6gg5K4V3XmCvS1m2tuWOJccP1XuzJfl9e3Phc9xfI3677ztfAdn9qNPfnpQqyuVpJu5dzWuTiQSHW7BoYu2EEiKLharYsSI2DsXTwqSJtzDo3a8f_JhjyuYnnmxuHLGpQ-2MXiqWOY0NZz2qug6dqh37qk9-25gxUOHvOWcI5765AU3Od6Hi2bGDL0uChsbwVrOaTq-ZKxiMo.tnICf2BFsVwtsr5VfyZAkryQOeGCHnSjB7Rr5wbPP34&dib_tag=se&keywords=the+lady+tasting+tea&qid=1765394770&sprefix=the+lady+tast%2Caps%2C122&sr=8-1) + [Thicker than Blood: How Racial Statistics Lie](https://www.amazon.com/Thicker-Than-Blood-Racial-Statistics/dp/0816639094/ref=sr_1_1?crid=QJZDL23TK86C&dib=eyJ2IjoiMSJ9.DHq92bbRD63ch9FSl6s-upc2huynGsD-FnMMQ8oGkWXMJpml25UsNSuXEL2lvzQs7xWH2VUww24p7e1MdBi6vhDzul6E00uAT70mo3ZprItslR1hTgUvxO7XM27oRh69qZIJBsafsnFWcblrnZQPQD5uS_RnBA1gLcWA6AdC8NVm15LPwnw64La49nKPzyLHHXiGqdJnxfptd0VAupO0NLYv37IuU6anRYKZV2MzV1w.SssIAE8yIKkuVaMayzCk-h8KKsc34iXVpdx5499WEic&dib_tag=se&keywords=thicker+than+blood&qid=1765394786&sprefix=thicker+than+blood%2Caps%2C112&sr=8-1) + [Weapons of Math Destruction](https://www.amazon.com/Weapons-Math-Destruction-Increases-Inequality/dp/0553418831/ref=sr_1_1?crid=2N1WP8NGZ1XXT&dib=eyJ2IjoiMSJ9._Ib1rdVR1ZEU9t48f_U3Pmins7VDe8N2cKKYOjkNtS6AiOOormoIN6FltOpzqJtx8QU3tHvxjeQPcflsJZl3FVSO76vJeOcPA24Ha2WS61czkcDglr3qHqLE0e6uyb-TKFUIrcABi6DX9jkRpJPZcDfAe73iv8tg5ej_yMYn3fJXcC0WaDpaYLw8a0bA9DViZX5jRNKdmDUGvHsFOWz5fTyWzhWDcwPlfBW9-QROa4k.PCBIMitn9CxJFz4eYVkrMnVmtwOgHNOjY4sp3ufFuiw&dib_tag=se&keywords=weapons+of+math+destruction&qid=1765394803&sprefix=weapons+of+math%2Caps%2C121&sr=8-1) --- # Miscellaneous resources + [Tidyverse style guidelines](https://style.tidyverse.org) + Create nicely formatted tables w/ kableExtra + [LaTeX / pdf tables](https://haozhu233.github.io/kableExtra/awesome_table_in_pdf.pdf) + [HTML tables](https://cran.r-project.org/web/packages/kableExtra/vignettes/awesome_table_in_html.html) --- # Final thoughts + Keep learning -- + Keep programming (reproducibly!) -- + Keep being thoughtful about data ethics