For the purposes of this guide, we will be using the Data.csv file. data will be the name of the variable we use for the csv. response_variable and explanatory_variable are named for the Data.csv file. Sometimes I may use different variable names for specific tests. This is for convenience. HYPOTHESIS TESTING Binomial probabilities dbinom(x=6, size=10, p =. 3) · gives P(X = 6) for X ~ Binomial (10, .3). pbinom(x=6, size=10, p =. 3) · gives P(X ? 6). · 1 - this gives P(X?7). sum(dbinom(7:10, size = 10, prob = 0.3)) · gives P(X?7). Note, you don't have to put x=, size=, or p =. Simply putting numbers in works. z values and significance qnorm(0.975) . gives the z statistic corresponding to quantile 0.975 on the Normal distribution. pnorm(1.96) · gives the quantile corresponding to the z statistic 1.96 on the Normal distribution. Finding t values for quantiles pt( t-statistic, df = _ ) · Gives the quantile corresponding to the t-statistic, given the degrees of freedom. qt( quantile, df = ) · Gives the standard deviations needed for that confidence quantile. t test t.test (response_variable ~ explanatory_variable, data = data, alternative = 'less' or 'greater') · The explanatory variable must have only two choices. Any more and you should refer to ANOVA. . This is the Welch approximation t test. For pooled t test, use 'var.equal = TRUE'. . The default t test is two sided, for a one-tailed test, use either 'less' or 'greater' depending on the alternative hypothesis. · Remember that groups are arranged alphabetically, first group - second group, so greater or less may change. One-way ANOVA / regression ANOVA summary(aov(response_variable ~ explanatory_variable, data = data))
· Explanatory variable can be anything with two or more distinct categories. · One-way ANOVA or regression ANOVA depending on whether the explanatory variable is categorical or quantitative. pf(25, df1 = 2, df2 = 12) · Finds the p-value for an f-ratio of 25, a groups degrees of freedom of 2, and a residuals degrees of freedom of 12. Two-way ANOVA summary(aov(response_variable ~ explanatory_variable*explanatory_variable2, data = data)) . Note the explanatory_variable2 in testing a two-way ANOVA. . + can be used instead of * if there is for sure no interaction affect (see linear regression). Linear regression summary(lm(response_variable ~ explanatory_variable, data=data)) · Gives more information about the linear model, including standard errors, residual standard error, t-values, and two-sided p-values. . We care about the standard error and two-sided p-value for the slope if we are working out a test for association. · Can be used for both [quantitative x quantitative] or [quantitative x categorical] (which will be translated to 0 and 1). summary(lm(response_variable ~ explanatory_variable * explanatory_variable2, data = data)) · Allows testing of multiple explanatory variables in a linear regression association test. . Includes adjustment for an interaction effect between the explanatory variables. summary(lm(response_variable ~ explanatory_variable + explanatory_variable2, data = data)) · Drops the interaction between explanatory variables, useful if there is indeed no interaction. · Simplifies testing