\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{Jeffrey M. Pisklak (non\_human\_entity)} \pdfinfo{ /Title (r-cheat-sheet-v2-electric-boogaloo.pdf) /Creator (Cheatography) /Author (Jeffrey M. Pisklak (non\_human\_entity)) /Subject (R V2: Electric Boogaloo Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{458A0E} \definecolor{LightBackground}{HTML}{F3F7EF} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{R V2: Electric Boogaloo Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{Jeffrey M. Pisklak (non\_human\_entity)} via \textcolor{DarkBackground}{\uline{cheatography.com/127433/cs/25553/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}Jeffrey M. Pisklak (non\_human\_entity) \\ \uline{cheatography.com/non-human-entity} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Not Yet Published.\\ Updated 28th December, 2023.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{tabularx}{17.67cm}{p{3.1086 cm} x{14.1614 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Operators}} \tn % Row 0 \SetRowColor{LightBackground} = & Assigns a value to an object \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{17.67cm}}{\textless{}-} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} x \textgreater{} y & x greater than y \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} x \textless{} y & x is less than y \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} x \textgreater{}= y & x greater than or equal to y \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} x \textless{}= y & x is less than or equal to y \tn % Row Count 6 (+ 1) % Row 6 \SetRowColor{LightBackground} != x & not equal to x \tn % Row Count 7 (+ 1) % Row 7 \SetRowColor{white} !x & not x \tn % Row Count 8 (+ 1) % Row 8 \SetRowColor{LightBackground} x | y & x OR y \tn % Row Count 9 (+ 1) % Row 9 \SetRowColor{white} x \& y & x AND y \tn % Row Count 10 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{17.67cm}}{\bf\textcolor{white}{Basic R Functions}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{Access a function's help file} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`help(​fun​ction name)`} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{Load a csv file} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`read.csv("snails.csv", header = TRUE, row.names = NULL)`} \tn % Row Count 5 (+ 3) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{Install a library} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}\seqsplit{`insta​ll.p​ac​kag​es​(​"​library} name")`} \tn % Row Count 8 (+ 3) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{Load an installed library} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}\seqsplit{`libra​ry​(​l​ibrary} name)`} \tn % Row Count 10 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{Resize images in Jupyter and Google Collab} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}\seqsplit{`optio​ns​(​r​ep​r}.p​lo​t.width = x, \seqsplit{repr.p​lo​t.h​eight} = y)`} \tn % Row Count 13 (+ 3) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{Return the amount of values in x} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`lengt​h(x)`} \tn % Row Count 15 (+ 2) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{Return the number of rows in a dataframe} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`nrow(df)`} \tn % Row Count 17 (+ 2) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{Return the absolute value(s) in x} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`abs(x)`} \tn % Row Count 19 (+ 2) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{Return the sum of all the values in x} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`sum(x)`} \tn % Row Count 21 (+ 2) % Row 9 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{Return the square​-root of the value(s) in x} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`sqrt(x)`} \tn % Row Count 23 (+ 2) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{Return the mean of the values in x with optional arguments for trimming and removing NAs} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`mean(x, tr = 0, na.rm = FALSE)`} \tn % Row Count 26 (+ 3) % Row 11 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{Return the median of the values in x with optional arguments removing NAs} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`median(x, na.rm = FALSE)`} \tn % Row Count 29 (+ 3) % Row 12 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{Return the sample standard deviation of values in x with optional argument for removing NAs} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`sd(x, na.rm = FALSE)`} \tn % Row Count 32 (+ 3) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{17.67cm}}{\bf\textcolor{white}{Basic R Functions (cont)}} \tn % Row 13 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{Return the sample variance of values in x with optional argument for removing NAs} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`var(x, na.rm = FALSE)`} \tn % Row Count 3 (+ 3) % Row 14 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{Return the quartiles for x with optional argument for removing NAs} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`quant​ile(x, na.rm = FALSE)`} \tn % Row Count 6 (+ 3) % Row 15 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{Sort the values of x into ascending order} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`sort(x)`} \tn % Row Count 8 (+ 2) % Row 16 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{Compute the median absolute deviation of x with optional argument to remove NAs} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`mad(x, na.rm = FALSE)`} \tn % Row Count 11 (+ 3) % Row 17 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{Find NA values in x (returns TRUE/F​ALSE)} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`is.na(x)`} \tn % Row Count 13 (+ 2) % Row 18 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{Paste things together into a single string} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`paste(x, y, z, sep = "")`} \tn % Row Count 15 (+ 2) % Row 19 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{Create a table of counts} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Examples: \{\{nl\}\}`table(x)` \{\{nl\}\} `table(x, y)`} \tn % Row Count 17 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{17.67cm}}{\bf\textcolor{white}{Data Frames}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{Create a new data frame} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`Column\_1 = c("A​", "​B", "C") \{\{nl\}\}Column\_2 = c(21, 22, NA)\{\{nl\}\}new\_df = \seqsplit{data.f​ram​e(C​olu​mn\_1}, Column\_2)`} \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{Add a column} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}\seqsplit{`new\_d​f\$C​olumn\_3} = c(51, 52, 53)`} \tn % Row Count 6 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{Select a specific value (e.g., 52 = row 2, column 3)} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`new\_df{[}2, 3{]}`} \tn % Row Count 9 (+ 3) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{Select a series of values (e.g., all of row 2)} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`new\_df{[}2, c(1,2,3){]}`\{\{nl\}\} or\{\{nl\}\} `new\_df{[}2, {]}`} \tn % Row Count 12 (+ 3) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{Select an entire column (e.g., column 2)} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`new\_d​f\$C​olu​mn\_2`\{\{nl\}\} or\{\{nl\}\} `new\_df{[} , 2{]}`} \tn % Row Count 15 (+ 3) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{Isolate column values that are not NAs} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`new\_d​f\$C​olu​mn\_​2{[}!​is.n​a(​new​\_df​\$Co​lum​n\_2){]}`} \tn % Row Count 18 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{17.67cm}}{\bf\textcolor{white}{Subset Function}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{Used to select specific observ​ations from a dataframe according to a rule you specify.} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}\seqsplit{`subse​t(d​ata​frame}, subset rule, select = ("co​lumns to keep"))`} \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{Example:} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`outliers = \seqsplit{subset​(he​igh​tData}, Father \textless{} 60.1 | Father \textgreater{} 75.3, select = c("F​ath​er"))`} \tn % Row Count 8 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{17.67cm}}{\bf\textcolor{white}{Library Functions}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{{\bf{libr​ary​(car)}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{Levene's Test} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}\seqsplit{`leveneTest(data\_frame\$Response}, data\_frame\$Predictor, center = median)`} \tn % Row Count 4 (+ 3) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{Bootstrapping a Regression Model} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`x = Boot(model, R = 2000) \{\{nl\}\} hist(x) \{\{nl\}\} confint(x) \{\{nl\}\} summary(x)`} \tn % Row Count 7 (+ 3) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{Type III Sum of Squares ANOVA} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`Anova(model, type = "III")`} \tn % Row Count 9 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{{\bf{libr​ary​(ef​fsi​ze)}}} \tn % Row Count 10 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{Cohen's d and Hedges g} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`cohen.d(y\textasciitilde{}x, data, hedges.co​rre​ction = FALSE)`} \tn % Row Count 13 (+ 3) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{{\bf{libr​ary​(pl​yr)}}} \tn % Row Count 14 (+ 1) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{Aggregate data frames} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`new\_df = ddply(​dat​aframe, c("Predictor1, Predictor2"), summarise, \{\{nl\}\} ~ n = \seqsplit{length​(Sc​ore​\_Co​lumn)}, \{\{nl\}\} ~ Means = mean(Score\_Column) )`} \tn % Row Count 19 (+ 5) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{{\bf{library(polycor)}}} \tn % Row Count 20 (+ 1) % Row 9 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{Biserial Correlation} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`polyserial(y, x)`} \tn % Row Count 22 (+ 2) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{{\bf{library(pwr)}}} \tn % Row Count 23 (+ 1) % Row 11 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{Sample Size for a Two-Sample T-test} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`pwr.t.test(d, sig.level, power, type = c("two.sample, "paired"))`} \tn % Row Count 26 (+ 3) % Row 12 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{Sample Size for a One-Way ANOVA} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`pwr.anova.test(k, f, sig.level, power)`} \tn % Row Count 28 (+ 2) % Row 13 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{{\bf{libr​ary​(rc​omp​ani​on)}}} \tn % Row Count 29 (+ 1) % Row 14 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{Calculates lambda for Tukey's ladder of powers} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}\seqsplit{`trans​for​mTu​key(x}, plotit = FALSE, return​Lambda = TRUE)`} \tn % Row Count 32 (+ 3) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{17.67cm}}{\bf\textcolor{white}{Library Functions (cont)}} \tn % Row 15 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{{\bf{libr​ary​(WR​S2)}}} \tn % Row Count 1 (+ 1) % Row 16 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{Winsorized variance of x} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`winvar(x, tr = .2)`} \tn % Row Count 3 (+ 2) % Row 17 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{Yuen's two sample t-test for trimmed independent means} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`yuen(y \textasciitilde{} x, tr = .2)`} \tn % Row Count 6 (+ 3) % Row 18 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{One-Way Robust Independent ANOVA with bootstrapping: F-tests} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`t1waybt(Response \textasciitilde{} Predictor, data = data, tr = 0.2, nboot = 2000)`} \tn % Row Count 10 (+ 4) % Row 19 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{One-Way Robust Independent ANOVA with bootstrapping: Post Hocs} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`mcppb20(Response\textasciitilde{} Predictor, data = data, tr = 0.2, nboot = 2000)`} \tn % Row Count 14 (+ 4) % Row 20 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{Two-Way Robust Independent ANOVA: F-tests} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`t2way(Response \textasciitilde{} Predictor A+ Predictor B + Predictor A : Predictor B, data = depress, tr = 0.2)`} \tn % Row Count 18 (+ 4) % Row 21 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{Two-Way Robust Independent ANOVA: Post-Hocs} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`x = mcp2atm(Response \textasciitilde{} Predictor A+ Predictor B + Predictor A : Predictor B, data = depress, tr = 0.2) \{\{nl\}\} x\$contrasts \{\{nl\}\} x`} \tn % Row Count 22 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{17.67cm}}{\bf\textcolor{white}{Distribution Functions}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{{\bf{Return the the corres​ponding {\emph{quantile}} for a given probab​ility}}} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{Normal Distribution} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}\seqsplit{`qnorm​(pr​oba​bility}, mean, sd)`} \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{T Distribution} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`qt(pr​oba​bility, df, lower.tail)`} \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{F Distribution} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`qf(probability, df1, df2, lower.tail)`} \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{Chi-Square Distribution} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`qchisq(probability, df, lower.tail)`} \tn % Row Count 10 (+ 2) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{{\bf{Return the the corres​ponding {\emph{probab​ility}} for a given quantile.}}} \tn % Row Count 12 (+ 2) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{Normal Distribution} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`pnorm​(quantile, mean, sd)`} \tn % Row Count 14 (+ 2) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{T Distribution} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`pt(quantile, df, lower.tail)`} \tn % Row Count 16 (+ 2) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{F Distribution} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`pf(quantile, df1, df2, lower.tail)`} \tn % Row Count 18 (+ 2) % Row 9 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{Chi-Square Distribution} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`pchisq(quantile, df, lower.tail)`} \tn % Row Count 20 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Regression and ANOVA Functions}} \tn % Row 0 \SetRowColor{LightBackground} Factoring a Predictor & \seqsplit{`data\_frame\$Predictor} = \seqsplit{factor(data\_frame\$Predictor)`} \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} Viewing levels of a factor & \seqsplit{`levels(data\_frame\$Predictor)`} \tn % Row Count 5 (+ 2) % Row 2 \SetRowColor{LightBackground} Linear Model & `model = lm(Response \textasciitilde{} Predictor1 + Predictor2, data = data)` \tn % Row Count 9 (+ 4) % Row 3 \SetRowColor{white} Summary output of a linear model & `summary(model)` \tn % Row Count 11 (+ 2) % Row 4 \SetRowColor{LightBackground} Linear Model Confidence Intervals & `confint(model)` \tn % Row Count 13 (+ 2) % Row 5 \SetRowColor{white} F-test Model Comparisons & `anova(model1, model2, model3, etc...)` \tn % Row Count 15 (+ 2) % Row 6 \SetRowColor{LightBackground} Anova main effects & \seqsplit{`summary(aov(model))`} \tn % Row Count 17 (+ 2) % Row 7 \SetRowColor{white} Dummy Coding with 1s and 0s & \seqsplit{`ifelse(data\_frame\$Predictor} == "X", 1, 0)` \tn % Row Count 20 (+ 3) % Row 8 \SetRowColor{LightBackground} Contrasts & `cont1 = c(1, 1, -2) \{\{nl\}\} cont2 = c(1, -1, 0) \{\{nl\}\} \seqsplit{contrasts(data\_frame\$Predictor)} = cbind(cont1, cont2)` \tn % Row Count 26 (+ 6) % Row 9 \SetRowColor{white} Polynomial Contrasts & \seqsplit{`contrasts(data\_frame\$Predictor)} = \seqsplit{contr.poly(levels(data\_frame\$Predictor))`} \tn % Row Count 30 (+ 4) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Regression and ANOVA Functions (cont)}} \tn % Row 10 \SetRowColor{LightBackground} Post Hoc Tests ("bonferroni", "holm", "BH") & \seqsplit{`pairwise.t.test(data\_frame\$Response}, \seqsplit{data\_frame\$Predictor}, p.adjust.method = c("holm"))` \tn % Row Count 5 (+ 5) % Row 11 \SetRowColor{white} Tukey HSD & \seqsplit{`TukeyHSD(aov(model)}, "Predictor")` \tn % Row Count 7 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{Note: the `lm()` function stores many useful things as attributes: \newline `model\$residuals` \newline `model\$coefficients`} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{17.67cm}}{\bf\textcolor{white}{Common Statistical Tests and Calculations}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{T-test} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`t.tes​t(y\textasciitilde{}x, altern​ative = c("two.sided"), mu = 0, var.equal = FALSE, conf.level = 0.95)`} \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{Correlation} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`cor(x, y)`} \tn % Row Count 6 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{Goodness-Of Fit (One Variable)} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`chisq.test(x = observed, p = expected probabilities)`} \tn % Row Count 9 (+ 3) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{Pearson's Chi-squared test (Two Variables)} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`chisq.test(table , correct = FALSE)`} \tn % Row Count 11 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{Fisher's Exact Test} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`fisher.test(table)`} \tn % Row Count 13 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{17.67cm}}{\bf\textcolor{white}{Plotting: librar​y(g​gplot2)}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{Histogram} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}\seqsplit{`ggplo​t(d​ata​Frame}, aes(x = Dep\_Var)) +\{\{nl\}\} ~ ~ \seqsplit{geo​m\_h​ist​ogr​am(​colour} = "​bla​ck", \{\{nl\}\} ~ ~ fill = "white")`} \tn % Row Count 5 (+ 5) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{Density Plot} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}\seqsplit{`ggplo​t(d​ata​Frame}, aes(x = Dep\_Var)) +\{\{nl\}\} ​~ ~ \seqsplit{geo​m\_d​ens​ity​(colour} = "​bla​ck",fill = "​pin​k", adjust = 1)`} \tn % Row Count 10 (+ 5) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{Boxplots} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}\seqsplit{`ggplo​t(d​ata​Frame}, aes(x = Indep\_Var, y = Dep\_Var)) +\{\{nl\}\} ​~ \seqsplit{~ geo​m\_b​oxp​lot()`}} \tn % Row Count 14 (+ 4) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{Barplot with errorb​ars} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}\seqsplit{`ggplo​t(p​lot​Data}, aes(x = Indep\_Var, y = Dep\_Var, fill = Indep\_​Var)) +\{\{nl\}\} ~ ~ geom\_b​ar(stat = "​ide​nti​ty", colour = "​bla​ck") +\{\{nl\}\} ~ ~ \seqsplit{geom\_e​rro​rba​r(a​es(ymin} = bottom\_value, ymax = top\_value), width = .25)`} \tn % Row Count 21 (+ 7) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{Q-Q Plot For two indepe​ndent samples \{\{nl\}\} \textasciicircum{}Remove `+ facet\_​wrap()` for a single sample\textasciicircum{}} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}\seqsplit{`ggplo​t(d​ata​Frame}, aes(sample = Dep\_Var)) + \{\{nl\}\} ~ ~ stat\_qq() +\{\{nl\}\} ~ ~ stat\_q​q\_l​ine() +\{\{nl\}\} ~ ~ facet\_​wrap(\textasciitilde{} Indep\_​Var)`} \tn % Row Count 27 (+ 6) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{Line Plot of Means with Two Predictors} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`ggplot(plotData, aes(x = PredictorA, y = Means, group = PredictorB, colour = PredictorB)) + \{\{nl\}\} ~ ~ geom\_line(position = position\_dodge(width = 0.4)) + \{\{nl\}\} ~ ~ geom\_point(position = position\_dodge(width = 0.4)) `} \tn % Row Count 34 (+ 7) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{17.67cm}}{\bf\textcolor{white}{Plotting: librar​y(g​gplot2) (cont)}} \tn % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{Scatterplot with Regression Line} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`ggplot(dataframe, aes(x = predictor, y = response)) + \{\{nl\}\} ~ ~ geom\_point() + \{\{nl\}\} ~ ~ geom\_abline(intercept = b0, slope = b1) `} \tn % Row Count 5 (+ 5) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \end{document}