Stats.Sum.notes

Basic R operations and data manipulation

This section covers fundamental R operators, data storage mechanisms, and initial steps for loading data and packages in R.

1.1 Basic operators

R utilizes several operators for performing arithmetic operations and storing data.

1.1.1 Arithmetic operators

  • Addition and Subtraction: The + or - operators are used for adding or subtracting values 1.
  • Multiplication: The * operator is used for multiplication 1.
  • Division: The / operator is used for division 1.
  • Exponentiation: The ^ operator is used to raise a number to a power 1.

1.1.2 Data storage operator

  • Assignment: The <- operator is used to store data or results into objects or variables 1.

Example: To store the text "apples" into an object named c, you would use c <- "apples" 1. Example: To store a sequence of numbers (1, 2, 3) into an object named c, you would use c <- c(1,2,3) 1.

1.1.3 Comments

  • The # symbol is used to ignore lines of code, effectively making them comments 1.

1.2 Vectors

Vectors are fundamental data structures in R that can hold multiple values, which can be either text (letters) or numbers 1.

  • Creating vectors: The c() function (which stands for combine) is used to create vectors by listing the values within the parentheses 1.
  • For text, values should be enclosed in double quotes ("") 1.
  • For numbers, no quotes are needed 1.

Example: To create a vector named d with the numeric values 3, 7, and 1, you would use d <- c(3,7,1) 1.

  • Accessing vector elements:
  • To recall a specific value from a vector, you use square brackets [] with the index (position) of the element. For example, d would recall the second data value from vector d, which is 7 1 2.

1.3 Data frames and indexing

Data frames are tabular data structures in R. Specific elements within a data frame can be accessed using a specific indexing syntax.

  • Accessing elements: The syntax dataframe[row, column] is used to recall a specific value from a table 1 2.

Example: d would recall the element at the second row and third column of a data frame named d 1 2 .

1.4 Loading data and packages

R provides functions to load external data files and to utilize pre-written functionalities from packages.

1.4.1 Loading data files

  • RData files: The load("filename.rdata") command is used to load data stored in an RData file 1.
  • CSV files: The read.csv("filename.csv", row.names = 1) command is used to import data from a CSV file. The row.names = 1 argument correctly sets the first column as row names 1.

1.4.2 Working directory management

  • Checking the current directory: The getwd() function returns the path of the current working directory 2.
  • Setting the working directory: The setwd("folder address") command is used to change the current working directory to a specified folder address 2.

1.4.3 Package management

  • Installing packages: The install.packages("package name") command is used to download and install a package from a repository 2.
  • Loading packages: The library("package name") command makes the functions and data within an installed package available for use in the current R session 2.

1.5 Investigating and manipulating data

R offers various tools for examining and modifying the structure and content of data.

1.5.1 Data examination

  • Subsetting data: The $ operator is used to extract a specific column from a data frame. For instance, cars$mpg retrieves the mpg column from the cars data frame 2.
  • Recalling column names: The names(dataframe) function returns a vector containing the names of all columns in the specified data frame 2.
  • Viewing data subsets:
  • head(dataframe) displays the column names and the first 6 rows of a data frame 2.
  • head(dataframe, n=x) displays the column names and the first x rows of a data frame. This can be used to view all rows if x is set to the total number of rows using nrow() 2.
  • Counting dimensions:
  • nrow(dataframe) returns the number of rows in a dataset 2.
  • ncol(dataframe) returns the number of columns in a dataset 2.
  • Converting data types: The dataframe$column <- factor(dataframe$column) command converts the data in a specified column into a factor class. This can also be applied to convert data into integer or numeric classes 2.
  • Checking data class: The class(dataframeUSDcolumn) function is used to determine the data type (class) of a variable or column 2.
  • Filtering data: The [which(dataframeUSDcolumn == "category")] syntax is used to select rows from a specific column that meet a certain condition or match a specific category 2.

1.5.2 Graphical presentation

  • Boxplots: The boxplot(dataframeUSDcolumn) command generates a boxplot for the data in a specified column.

Example: boxplot(miceUSDweight) creates a boxplot visualizing the distribution of weights from the mice dataset 2.


Data exploration and graphical presentation

This section outlines essential methods for exploring datasets, including data subsetting, inspecting column names and dimensions, converting data types, and generating various graphical presentations such as boxplots and histograms.

2.1 Data examination

Exploring a dataset is a crucial first step to understand its structure and content. Several functions and operators are used for this purpose.

2.1.1 Accessing and inspecting data

  • The $ operator is used to access specific columns (variables) within a data frame. For example, cars$mpg retrieves the mpg column from the cars dataset 2.
  • To recall a specific value within a table (data frame), you can use square bracket notation: dataframe[row number, column number] 2.
  • names(dataframe) displays all column names of a data frame 2.
  • head(dataframe) shows the column names and the top 6 rows of the data frame. You can specify the number of rows to display using head(dataframe, n=x) 2.
  • nrow(dataframe) returns the number of rows in a dataset 2.
  • ncol(dataframe) returns the number of columns in a dataset 2.

2.1.2 Data type conversion

  • Data can be converted into a factor class using the command dataframe$column <- factor(dataframe$column). This is also applicable for integer or numeric data types 2.
  • To check the data type of a variable, use class(dataframeUSDcolumn) 2.

2.1.3 Subsetting data based on conditions

  • You can select data from a specific column that meets certain criteria using which(dataframeUSDcolumn == "category"). This function returns the indices of the elements that satisfy the condition 2.

2.2 Graphical presentation

Visualizing data is vital for understanding distributions, relationships, and patterns.

2.2.1 Boxplots

Boxplots are useful for visualizing the distribution of a numerical variable and identifying potential outliers.

  • A basic boxplot for a single variable is created with boxplot(dataframe$column). For instance, boxplot(mice$weight) would generate a boxplot of mice weights 2.
  • To create boxplots grouped by another variable, the syntax boxplot(dataframe$column1 ~ dataframe$column2) or boxplot(dataframe$column2, data=dataframe) is used. Here, column1 is the response variable (dependent), and column2 is the explanatory variable (used for grouping). For example, boxplot(mice$weight, miceUSDgenotype) would group the weights by genotype 3.

Tip: When creating grouped boxplots, ensure the grouping variable is a factor or a categorical type for proper visualization.

2.2.2 Histograms

Histograms display the distribution of a numerical variable by dividing the data into bins.

  • A basic histogram is generated using hist(dataframeUSDcolumn) 3.
  • To create a histogram for a specific subset of data, such as a particular treatment group, you can combine hist() with the subsetting condition: hist(dataframe$column[which(dataframe$treatment == "treatment group type")]). For example, hist(data1$weight[which(data1$treatment=="control")]) would show the distribution of weights only for the control group 3.

2.2.3 Quantile-Quantile (Q-Q) plots

Q-Q plots are used to assess whether a dataset follows a specified theoretical distribution, typically the normal distribution.

  • qqnorm(dataframeUSDcolumn) generates a Q-Q plot for the specified column 3.
  • qqline(dataframeUSDcolumn) adds a reference line of best fit to the Q-Q plot 3.

2.2.4 Scatter plots

Scatter plots are used to visualize the relationship between two numerical variables.

  • The general syntax for a scatter plot is plot(a ~ b, data = dataframe), where b is the independent/explanatory variable (plotted on the x-axis) and a is the dependent/response variable (plotted on the y-axis). The tilde symbol ~ signifies "is explained by" 3.
  • Plot customization options include:
  • xlab = "x-axis title" to set the x-axis label 3.
  • ylab = "y-axis title" to set the y-axis label 3.
  • main = "graph title" to set the main title of the graph 3.
  • xlim = c(x, y) to set the limits of the x-axis 3.
  • ylim = c(x, y) to set the limits of the y-axis 3.
  • Text can be added to any location on the plot using text(coordinates, coordinates, "text") 3.

2.2.5 Pairwise scatter plots

  • pairs(dataframe) generates a matrix of scatter plots, showing pairwise relationships between all numerical columns in a data frame. This is a quick way to visualize multiple relationships simultaneously 3.

2.3 Summarising data

Summarizing data provides key statistical information about the variables in a dataset.

  • summary(dataframe) provides a comprehensive summary of all variables in the dataset, including minimum, maximum, mean, first quartile (Q1), median, and third quartile (Q3) 3.
  • summary(dataframe, column) provides a summary for a specific column 3.

Statistical summaries and correlation/regression

This section details how to generate descriptive statistics for datasets and individual variables, including group-wise summaries, and introduces the concepts and functions for analyzing correlations and linear regressions.

3.1 Summarizing data

3.1.1 Overall dataset summary

The summary() function in R provides a comprehensive overview of all variables within a dataset. For each column (variable), it typically outputs 3 4:

  • Minimum value: The smallest observation in the dataset 3.
  • 1st Quartile (Q1): The value below which 25% of the data falls 3.
  • Median: The middle value of the dataset when ordered 3.
  • Mean: The average of all observations 3.
  • 3rd Quartile (Q3): The value below which 75% of the data falls 3.
  • Maximum value: The largest observation in the dataset 3.

3.1.2 Summary for a specific column

To obtain a summary for a single column (variable) within a dataset, you can specify the column name within the summary() function 3: summary(dataframeUSDcolumn)

3.1.3 Grouped summaries

To calculate summary statistics for a variable, broken down by a grouping variable, the describeBy() function from the psych package is useful. This function provides detailed statistics for each group, including 4:

  • Variance 4.
  • Number of observations (n) 4.
  • Mean 4.
  • Standard deviation 4.
  • Median 4.
  • Trimmed mean 4.
  • Median absolute deviation 4.
  • Minimum and Maximum values 4.
  • Range 4.
  • Skewness and Kurtosis 4.
  • Standard error of the mean 4.

The aggregate() function can also be used to calculate specific statistics for groups.

  • Calculating Mean: aggregate(a ~ b, data = dataframe, FUN = mean) 4.
  • Calculating Standard Deviation (SD): aggregate(a ~ b, data = dataframe, FUN = sd) 4.
  • Calculating Standard Error of the Mean (SEM): This requires a custom function: aggregate(a ~ b, data = dataframe, FUN = function(x) sd(x) / sqrt(n)) where n is the number of observations in each group 4.
  • Calculating Confidence Interval (CI): This also requires a custom function, using a multiplier (e.g., 2.571 for a t-distribution or 2 for a large sample size) and the SD and n: aggregate(a ~ b, data = dataframe, FUN = function(x) CL = 2.571 * sd(x) / sqrt(n)) 4.

The do.call() function can be used to apply multiple aggregate functions at once and store the results in a data frame 24 4.

3.2 Correlation and Regression

Correlation and regression analysis are used to understand the relationship between two or more variables.

3.2.1 Correlation

Correlation measures the strength and direction of the linear relationship between two variables 17.

  • Calculating correlation between two variables: The cor(a, b) function calculates the Pearson correlation coefficient between variables a and b 4.
  • Calculating correlation for all pairs of variables in a dataframe: The cor(dataframe) function computes the correlation matrix for all possible pairs of columns within the specified dataframe 17 4.

3.2.2 Linear Regression

Linear regression models the relationship between a dependent variable and one or more independent variables by fitting a linear equation to the observed data.

  • Fitting a linear model: The lm() function is used to build a linear regression model. The syntax lm(column1 ~ column2, data = dataframe) specifies that column1 (the response variable) is explained by column2 (the explanatory variable) within the dataframe. The model equation is stored in an object (e.g., fit) 17 18 19 20 21 22 23 24 4.
  • Interpreting the regression model: The summary(fit) function provides a detailed output of the regression analysis, including coefficients, standard errors, t-values, p-values, and the R-squared value 17 18 19 20 21 22 23 24.
  • The "coefficients" section details the intercept and slope of the regression line 17.
  • The adjusted R-squared value indicates how well the data fits the line, ranging from 0 to 1, where 1 represents a perfect fit. However, limitations exist: large variations around the line can result in a low R-squared value, and a high R-squared doesn't guarantee the line is a good fit if there are consistent differences 17.
  • Visualizing the regression line: A scatter plot of the two variables can be created using plot(column1 ~ column2, data = dataframe), and the fitted regression line can be added using abline(fit) 17 18 19 20 21 22 23 24 5.
  • Predicting new values: The predict() function uses the fitted model to estimate the dependent variable for new, unseen independent variable values 17 18 19 20 21 22 23 24.
  • A new data frame must be created for the input values: newdata <- data.frame(column=c(value)) 17 5.
  • The prediction can include confidence intervals: predict(object, newdata, interval = "confidence") 17 5.
  • Analyzing residuals: Residuals (the difference between observed and predicted values) can be plotted against the fitted values to check model assumptions: plot(fit$residuals ~ fit$fitted.values). A horizontal line at y=0 should be added using abline(h = 0) 17 18 19 20 21 22 23 24 5.

3.2.3 Plotting relationships

  • Scatter plots: Visualize the relationship between two variables. The format plot(dependent_variable ~ independent_variable, data = dataframe) is used 17 3.
  • Pairwise scatter plots: Generate scatter plots for all combinations of variables in a dataframe using pairs(dataframe) 17 3.
  • Limiting plot axes: Use xlim = c(min, max) and ylim = c(min, max) to set the display range for the x and y axes, respectively 3.
  • Adding text to plots: The text(x_coordinate, y_coordinate, "Your text") function allows adding custom text labels to specific locations on a plot 3.

Probability distributions and hypothesis testing

This section covers the fundamentals of probability distributions, specifically binomial and normal distributions, and then delves into the principles of hypothesis testing, including its components, potential errors, and related metrics.

4.1 Probability distributions

Probability distributions are graphical representations of the probabilities of different outcomes within a dataset or experiment. They are theoretical and describe the likelihood of each possible result 10.

4.1.1 Binomial distribution

The binomial distribution is used for discrete data and models scenarios with a fixed number of independent trials, each having only two possible outcomes: "success" and "failure" 10.

Conditions for a binomial distribution:

  • There are exactly two outcomes for each trial: success and failure 10.
  • The number of trials is fixed 10.
  • Each trial is independent of the others 10.
  • The probability of success (pp) is the same for every trial 10.

Key functions for binomial distribution:

  • dbinom(x, size, prob): Calculates the probability of an exact number of successes.
    • x: The exact number of successes.
    • size: The total number of trials.
    • prob: The probability of success in a single trial.
  • pbinom(q, size, prob): Calculates the cumulative probability, meaning the probability of getting up to and including a certain number of successes.
    • q: The maximum number of successes to include.
  • To find the probability of more than a certain number of successes (e.g., P(X>x)P(X > x)), you can use 1 - pbinom(x, size, prob) 5.
  • To find the number of successes required for a certain cumulative probability, you can use qbinom(cumulative probability, size, prob) 5.

Visualizing binomial distributions:

  • barplot(dbinom(x_values, size, prob)): Creates a bar plot showing the probability of each outcome in the distribution 6.
  • barplot(pbinom(q_values, size, prob)): Plots cumulative probabilities 6.

Tip: When defining success and failure for a binomial distribution, ensure they are mutually exclusive and cover all possibilities within a trial.

4.1.2 Normal distribution

The normal distribution, also known as the Gaussian distribution or bell curve, is used for continuous data that is often normally distributed. It is characterized by its mean and standard deviation 10 6.

Key function for normal distribution:

  • pnorm(q, mean, sd, lower.tail = TRUE): Calculates the cumulative probability for a normal distribution.
    • q: The value up to which to calculate the probability.
    • mean: The mean of the distribution.
    • sd: The standard deviation of the distribution.
    • lower.tail = TRUE (default): Calculates P(X≤q)P(X \le q).
    • lower.tail = FALSE: Calculates P(X>q)P(X > q) (upper tail probability).

Tip: For continuous data, the probability of any single exact value is theoretically zero. We are interested in ranges of values.

4.2 Hypothesis testing

Hypothesis testing is a statistical method used to make conclusions or predictions about a population based on sample data. It involves formulating hypotheses and using sample evidence to determine if the hypotheses can be rejected 10.

4.2.1 Null and alternative hypotheses

  • Null hypothesis (H0H_0): This is the default assumption, typically stating that there is no effect, no difference, or no relationship. It is assumed to be true until evidence suggests otherwise 10 15.
  • Alternative hypothesis (HAH_A or H1H_1): This is a statement that contradicts the null hypothesis, proposing that there is an effect, a difference, or a relationship. The null and alternative hypotheses are mutually exclusive 10 15.

Steps in hypothesis testing:

  1. Formulate hypotheses: Define the null (H0H_0) and alternative (HAH_A) hypotheses 15.
  2. Set significance level (α\alpha): This is the probability of rejecting the null hypothesis when it is actually true (Type I error). Commonly set at 0.05 10 15.
  3. Collect data: Gather sample data relevant to the hypotheses.
  4. Calculate test statistic: Compute a statistic based on the sample data.
  5. Determine p-value: The probability of observing a test statistic as extreme as, or more extreme than, the one calculated from the sample, assuming the null hypothesis is true 10 15.
  6. Make a decision:
  • If pp-value ≤α\le \alpha, reject H0H_0 in favor of HAH_A 10 15.
  • If pp-value >α> \alpha, fail to reject H0H_0 10 15.

Tip: The p-value does not measure the effect size or confirm the truth of the hypothesis; it only indicates how compatible the data is with the null hypothesis.

4.2.2 Type I and Type II errors

Errors can occur in hypothesis testing, leading to incorrect conclusions.

  • Type I Error (False Positive): Rejecting the null hypothesis (H0H_0) when it is actually true. The probability of a Type I error is denoted by α\alpha (the significance level). The sample size does not affect the probability of a Type I error 10 15.
  • Type II Error (False Negative): Failing to reject the null hypothesis (H0H_0) when it is actually false. The probability of a Type II error is denoted by β\beta. Increasing the sample size can reduce the probability of a Type II error 10 15.

4.2.3 Power

Statistical power is the probability of correctly rejecting a false null hypothesis; it is the complement of the Type II error rate (1−β1 - \beta) 10 15.

  • Higher power means a greater likelihood of detecting a real effect if one exists 15.
  • A powerful study is more reliable and increases certainty 15.

Factors that increase power:

  • Larger sample size 15.
  • Larger effect size 15.
  • Higher significance level (α\alpha) (though this also increases Type I error risk) 15.
  • Using a one-tailed test (when justified) 15.
  • Lower variance within the data 15.

4.2.4 Effect size

Effect size quantifies the magnitude or practical importance of a statistical difference or relationship, indicating how meaningful the finding is in the real world 10 15.

  • A study can achieve a statistically significant p-value with a small effect size, especially with large sample sizes, meaning the result is statistically detectable but not practically important 15.
  • Effect size can be measured using metrics like Cohen's dd, the correlation coefficient (rr), or R2R^2 15.

Factors that increase effect size:

  • A larger true difference between groups 15.
  • Lower variability in the data 15.
  • Less measurement error 15.
  • Improved study design, such as controlled experiments and reduced confounding variables 15.

Tip: While the p-value tells you if an effect is statistically significant, the effect size tells you if it is practically important.

4.3 Key concepts and functions in R

  • Binomial Distribution Functions:
    • dbinom(x, size, prob): Probability of an exact number of successes.
    • pbinom(q, size, prob): Cumulative probability up to qq successes.
    • qbinom(p, size, prob): The number of successes for a given cumulative probability pp.
  • Normal Distribution Function:
    • pnorm(q, mean, sd): Cumulative probability for a normal distribution.
  • Hypothesis Testing Function (Binomial):
    • binom.test(x, n, p, alternative): Performs a binomial test.
      • x: Number of successes.
      • n: Number of trials.
      • p: Hypothesized probability of success under H0H_0.
      • alternative: Specifies "less", "greater", or "two.sided" for one- or two-tailed tests.

Tip: When performing a one-tailed binomial test, ensure the alternative argument correctly reflects the direction of the alternative hypothesis.


Specific statistical tests and ANOVA

This section details the assumptions, applications, and interpretation of t-tests and Analysis of Variance (ANOVA), including methods for post-hoc analysis and multiple comparisons correction.

5.1 T-tests

T-tests are statistical methods used to evaluate if there is a statistically significant difference between up to two samples. They utilize the mean and standard deviation of a sample to estimate its representation of the population 10 15.

5.1.1 Types of T-tests

  • One-sample t-test: Used to compare a single sample's mean to a known population mean 10 15.
  • R Code: t.test(group, mu = x) where group is the data for the sample and mu is the population mean being compared against 7.
  • Two-sample t-test: Used to compare the means of two independent samples 10 15.
  • R Code: t.test(dataframe$sample1, dataframe$sample2) 7.
  • When performing a two-sample t-test in R, the assumption of equal variances is not automatically made. If variances are known to be equal, var.equal = TRUE can be added to the function, which may increase the test's power, though often with little advantage 10 15.
  • Paired t-test: Applied when samples are closely related, analyzing data in pairs, such as measurements before and after an intervention on the same individuals 10 15.
  • R Code: t.test(dataframe$sample1, dataframe$sample2, paired = TRUE) 7.
  • For a paired t-test, the order of pre_supplementation and post_supplementation typically does not affect the results 7.

5.1.2 Assumptions of T-tests

T-tests rely on several assumptions about the data:

  1. Continuous Dependent Variable and Bivariate Independent Variable: The dependent variable must be continuous, and the independent variable must be categorical with only two outcomes (bivariate). For example, comparing the effect of a "normal" diet versus a "western" diet (bivariate independent variable) on the time spent running on an exercise wheel (continuous dependent variable) 10 15.
  2. Normal Distribution: The population from which the samples are drawn is assumed to have a normal distribution. A normal quantile-quantile plot (Q-Q plot) can help assess if the data fits a normal distribution model by comparing dataset quantiles to theoretical normal distribution quantiles; a straight line indicates a good fit 10 15.
  3. Equal Variances (Homoscedasticity): The two populations from which the samples are drawn are assumed to have equal variances (spread of data). This can be checked by examining the variance or standard deviation of summary statistics. In R, describeBy() can be used to check summary statistics by group. A common heuristic is to consider variances equal if the ratio of the larger variance to the smaller variance is less than 4, though this is an estimation and may not be accurate for small sample sizes 10 15.

5.1.3 Interpreting T-test Output

  • Confidence Interval: The 95% confidence interval for the difference between means is provided. If this interval does not include 0, it suggests a statistically significant difference, indicating that the population mean difference is unlikely to be zero 10 15.
  • P-value: While the confidence interval is informative, the p-value is considered the most important indicator of significance 10 15.

5.2 Analysis of Variance (ANOVA)

ANOVA is a statistical test used to compare the means of three or more groups by comparing the variance within the groups to the variance between the groups. It determines if the observed differences between sample means are likely due to random variation or a genuine effect 10 15.

5.2.1 Performing ANOVA in R

Assumptions for ANOVA:

  • Data should be normally distributed 10 15.
  • Observations within each group and between groups should be independent 10 15.
  • Groups must have equal variances (homoscedasticity) 10 15.

R Code:

  • To perform an ANOVA test: aov(dependent_variable ~ independent_variable, data = dataframe) 8.
  • To view the results: summary(aov_test_output) 10 15.

Understanding ANOVA Output:

  • The output typically includes Sum of Squares, Degrees of Freedom (DF), Mean Squares, an F-statistic, and a p-value 10 15.
  • F-statistic: Calculated as the ratio of the variance between groups to the variance within groups. A high F-statistic suggests that variation between groups is larger than within groups, potentially indicating a statistically significant effect 10 15.
  • P-value: Indicates the probability of observing the data (or more extreme data) if the null hypothesis (all group means are equal) were true. A p-value below the significance level (alpha) leads to rejecting the null hypothesis 10 15.
  • Reporting ANOVA: Results are typically reported as F(dfbetween,dfwithin)=F-value,p=p-valueF(\text{df}_{\text{between}}, \text{df}_{\text{within}}) = \text{F-value}, p = \text{p-value}. For example: F(2,42)=39.45,p=2.21×10−10F(2, 42) = 39.45, p = 2.21 \times 10^{-10} 10 15.

5.2.2 Post-Hoc Tests

If an ANOVA test yields a significant result (i.e., a significant p-value), it indicates that at least one group mean differs from the others, but it does not specify which groups differ. Post-hoc tests are used to identify these specific differences 10 15.

  • Tukey's Honestly Significant Difference (HSD) Test: A common post-hoc test used after ANOVA.
  • R Code: TukeyHSD(aov_test_output) 8.
  • The output provides the differences between conditions and adjusted p-values. Adjusted p-values below the significance level indicate significant differences between specific group pairs 10 15.

5.3 Correcting for Multiple Comparisons

When performing multiple statistical tests, the probability of obtaining a false positive (Type I error) increases. This is known as the family-wise error rate (FWER). Methods to correct for multiple testing are employed to maintain a desired overall significance level 10 15.

  • Bonferroni Correction: This method controls the family-wise error rate by dividing the original alpha level by the number of tests performed. It is a strict method, reducing the chance of false positives but increasing the risk of false negatives (Type II errors), thus decreasing statistical power. It is best used when the number of tests is small and tolerance for false positives is very low 10 15.

  • Benjamini-Hochberg (BH) Correction: This method controls the false discovery rate (FDR), which is the expected proportion of false positives among the rejected null hypotheses. It is generally more powerful than Bonferroni, especially with a large number of tests, as it allows for some false positives while limiting their overall proportion. If an adjusted p-value (using BH) is below 0.05, it is expected that about 5% of these significant results might be false positives 10 15.

  • R Code: p.adjust(p_values, method = "bonferroni") or p.adjust(p_values, method = "BH"). The p_values would be a vector or column of p-values obtained from multiple tests 9.

5.4 Power and Sample Size Calculation

The pwr package in R can be used for power and sample size calculations. The pwr.t.test() function can be used for t-tests, requiring three of the four values: sample size (n), effect size (d for Cohen's d), significance level (sig.level), and power (power = 1 - β\beta) 7.


Common mistakes to avoid

  • Review all topics thoroughly before exams
  • Pay attention to formulas and key definitions
  • Practice with examples provided in each section
  • Don't memorize without understanding the underlying concepts

© 2026 Maeve. All rights reserved. This content is protected by copyright.

See also