
Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
A cheat sheet for essential statistics functions using r, including important libraries to load, the pipe operator (%>%), and various functions for descriptive statistics, filtering data frames, and conducting statistical tests. It also covers creating factors, fitting linear and logistic regression models, and power calculations.
What you will learn
Typology: Cheat Sheet
1 / 1
This page cannot be seen from the preview
Don't miss anything!
Function Description read_csv("path/nhanes.csv") Read nhanes.csv in the path/ folder ( readr ) View(df) View tabular data frame df in a graphical viewer head(df) ; tail(df) Print first and last few rows of data frame df mean, median, range Descriptive stats. Remember na.rm=TRUE if desired is.na(x) Returns TRUE/FALSE if NA. sum(is.na(x)) to count NAs filter(df, ..,) Filters data frame according to condition ... (dplyr) t.test(y~grp, data=df) T-test mean y across grp in data df wilcox.test(y~grp, data=df) Wilcoxon rank sum / Mann-Whitney U test lmfit <- lm(y~x1+x2, data=df) Fit linear model y against two x ’s anova(lmfit) Print ANOVA table on object returned from lm() summary(lmfit) Get summary information about a model fit with lm() TukeyHSD(aov(lmfit)) ANOVA Post-hoc pairwise contrasts xt <- xtabs(~x1+x2, data=df) Cross-tabulate a contingency table addmargins(xt) Adds summary margin to a contingency table xt prop.table(xt) Turns count table to proportions (remember margin=1) chisq.test(xt) Chi-square test on a contingency table xt fisher.test(xt) Fisher’s exact test on a contingency table xt mosaicplot(xt) Mosaic plot for a contingency table xt factor(x, levels=c("wt", "mutant")) Create factor specifying level order relevel(x, ref="wildtype") Re-level a factor variable glm(y~x1+x2, data=df, family="binomial") Fit a logistic regression model power.t.test(n, power, sd, delta) T-test power calculations power.prop.test(n, power, p1, p2) Proportions test power calculations tidy() augment() glance() Model tidying functions in the broom package