Explore statistics with R: Inferential statistics
Inferential statistics is a branch of statistics that focuses on making predictions or inferences about a population based on a sample of…
Explore statistics with R: Inferential statistics

Inferential statistics is a branch of statistics that focuses on making predictions or inferences about a population based on a sample of data. Unlike descriptive statistics, which merely summarize data, inferential statistics go a step further by using data to make generalizations, draw conclusions, and test hypotheses.
Key Concepts in Inferential Statistics
Inferential statistics involves several key concepts that form the foundation of its methods and applications, to include:
- Population and Sample:
- Population: A population refers to the entire group of individuals or items of interest in a particular study. It includes every member of the defined group.
- Sample: A sample is a smaller, manageable subset of the population selected for the purpose of conducting research. Sampling is used when it is impractical or impossible to collect data from the entire population.
- Parameter and Statistic:
- Parameter: A parameter is a numerical value that describes a characteristic of the population, such as the population mean (μ) or population variance (σ²).
- Statistic: A statistic is a numerical value that describes a characteristic of the sample, such as the sample mean (x̄) or sample variance (s²). Statistics are used to estimate population parameters.
- Sampling Distribution:
- The sampling distribution is the probability distribution of a given statistic based on a large number of samples drawn from the same population. It describes the variability of the statistic and forms the basis for making inferences about the population.
- Confidence Interval:
- A confidence interval is a range of values, derived from the sample, that is likely to contain the population parameter with a specified level of confidence (e.g., 95% confidence interval). It provides an estimate of the parameter along with an indication of the uncertainty associated with the estimate.
- Hypothesis Testing:
- Hypothesis testing is a method used to assess the evidence provided by the sample data to support or reject a specific hypothesis about the population. It involves formulating a null hypothesis (H₀) and an alternative hypothesis (H₁), and using a test statistic to determine whether to reject H₀.
Methods of Inferential Statistics
Several methods are commonly used in inferential statistics to make inferences about the population, to include:-
- Estimation:
- Estimation involves using sample data to estimate population parameters. Point estimation provides a single value estimate (e.g., sample mean), while interval estimation provides a range of values (e.g., confidence interval) that is likely to contain the parameter.
- Hypothesis Testing:
- Hypothesis testing involves comparing the observed sample data to a null hypothesis to determine whether there is enough evidence to reject the null hypothesis. Common tests include t-tests, chi-square tests, and ANOVA.
- Regression Analysis:
- Regression analysis is used to examine the relationship between one or more independent variables and a dependent variable. It helps in predicting the dependent variable based on the values of the independent variables.
- Analysis of Variance (ANOVA):
- ANOVA is used to compare the means of three or more groups to determine whether there are statistically significant differences between them. It is commonly used in experimental studies.
Importance of Inferential Statistics
Inferential statistics is important for several reasons, to include:
- Generalization:
- Inferential statistics allows researchers to make generalizations about a population based on sample data. This is crucial when studying large populations where collecting data from every member is impractical.
- Decision-Making:
- Inferential statistics provide a scientific basis for making data-driven decisions. It helps in assessing the evidence, estimating uncertainties, and drawing reliable conclusions.
- Hypothesis Testing:
- Hypothesis testing is a cornerstone of scientific research. It enables researchers to test theories, validate findings, and advance knowledge in various fields.
- Prediction:
- Inferential statistics is used to make predictions about future events or outcomes based on historical data. This is valuable in fields such as economics, medicine, and environmental science.
Data is vital for several reasons:
-
Informed Decision-Making: Data-driven decision-making involves using data to guide actions and strategies. Whether in business, healthcare, or public policy, decisions based on data are more likely to lead to successful outcomes.
-
Scientific Research: Data is the cornerstone of scientific research. Researchers collect and analyse data to test hypotheses, validate findings, and advance knowledge in various fields. Reliable data ensures that scientific conclusions are based on robust evidence.
-
Identifying Trends and Patterns: Data analysis helps identify trends and patterns within complex datasets. For example, businesses can use data to understand consumer behaviour, and epidemiologists can track disease outbreaks.
-
Predictive Analysis: Data enables predictive analysis, which involves using historical data to predict future events. This is crucial in fields such as finance, weather forecasting, and supply chain management.
Different Kinds of Data
Data can be classified into several types based on their characteristics and the level of measurement. Here are the main types of data:
- Nominal Data:
-
Nominal data represents categories or names that do not have a specific order or ranking.
-
Examples of nominal data include gender (male, female), eye colour (blue, green, brown), and types of cuisine (Italian, Chinese, Mexican).
- Ordinal Data:
-
Ordinal data represents categories with a meaningful order or ranking, but the differences between the ranks are not necessarily equal.
-
Examples of ordinal data include education level (high school, bachelor’s, master’s, doctorate), satisfaction ratings (poor, fair, good, excellent), and class ranks (first, second, third).
- Interval Data:
-
Interval data represents numerical values with equal intervals between them, but there is no true zero point.
-
Examples of interval data include temperature in Celsius or Fahrenheit, IQ scores, and calendar years.
- Ratio Data:
-
Ratio data is similar to interval data, but it has a true zero point, allowing for meaningful comparisons of ratios.
-
Examples of ratio data include height, weight, age, income, and distance.
- Continuous Data:
-
Continuous data can take any value within a range and are often measured rather than counted.
-
Examples of continuous data include height, weight, temperature, and time.
- Discrete Data:
-
Discrete data consists of distinct, separate values that are often counted rather than measured.
-
Examples of discrete data include number of children in a family, number of cars in a parking lot, and number of students in a classroom.
- Qualitative Data:
-
Qualitative data describes qualities or characteristics and is often categorical.
-
Examples of qualitative data are colours, names, labels, and descriptions.
- Quantitative Data:
- Quantitative data represents numerical values and can be measured or counted.
— Examples of quantitative data include age, salary, number of items sold, and distance.

What is the difference between a population and a sample?
In the realm of statistics, two fundamental concepts form the basis of data analysis: population and sample. Understanding the difference between these two terms is crucial for conducting accurate and meaningful statistical analyses. A population encompasses the entire group of individuals or items under study, while a sample is a subset of the population.

A population in statistics refers to the complete set of all possible observations or individuals that are of interest in a particular study. It includes every member of a defined group, whether they are people, objects, events, or measurements. For example, if a researcher is studying the average height of all adults in a country, the population would include every adult in that country. Populations can be finite or infinite, depending on the scope of the study.
In contrast, a sample is a smaller, manageable subset of the population that is selected for the purpose of conducting research. Sampling is used when it is impractical or impossible to collect data from the entire population. For instance, instead of measuring the height of every adult in a country, a researcher might select a representative sample of a few thousand adults to estimate the average height.
The distinction between a population and a sample is significant for several reasons. First, statistical analyses aim to make inferences about the population based on the data collected from the sample. These inferences are only valid if the sample accurately represents the population. Therefore, proper sampling techniques are essential to ensure that the sample reflects the characteristics of the population.
Second, understanding the difference between a population and a sample helps researchers determine the appropriate statistical methods to use. Population parameters (such as the population mean and variance) are estimated using sample statistics (such as the sample mean and variance). The accuracy of these estimates depends on the sample size and the representativeness of the sample.
Methods of Sampling

There are various sampling methods used to ensure that a sample is representative of the population:
- Simple Random Sampling: Every member of the population has an equal chance of being selected. This method is ideal for eliminating bias and ensuring that the sample is representative.


- Stratified Sampling: The population is divided into distinct subgroups (strata), and a random sample is taken from each stratum. This method ensures that all subgroups are adequately represented in the sample.



- Systematic Sampling: A random starting point is chosen, and every kth member of the population is selected. This method is easier to implement but may introduce bias if there is a pattern in the population.



- Cluster Sampling: The population is divided into clusters, and a random sample of clusters is selected. All members of the chosen clusters are then included in the sample. This method is useful when the population is large and dispersed.



- Convenience Sampling: The sample is selected based on ease of access and availability. While this method is convenient, it may not yield a representative sample and can introduce bias.



See the video on sampling in R:- https://youtu.be/Dx7OVCYZWxg
Bias in sampling
Bias in sampling means that a sample is systematically different from the population being studied. Bias happens when some members of the population are more likely to be included in the sample than others; not by random chance, but by the way the sample was chosen.
Sampling bias matters because:-
· It skews results and leads to wrong conclusions
· It reduces validity because the findings don’t generalise to the population
· It can make a study look scientific even when the data is lawed
Common types of sampling bias include:-
· Selection bias, where the method of choosing participants favours certain groups
· Undercoverage bias, where some groups are left out entirely
· Nonresponse bias, where people who don’t respond differ from those who do
· Voluntary response bias, where participants choose themselves, often because they have strong opinions
· Survivorship bias, where only successful or remaining subjects are observed
Ways to reduce sampling bias include:-
· Use random sampling whenever possible
· Ensure every member of the population has an equal chance of selection
· Increase response rates, which can be reminders or incentives
· Use stratified sampling to represent key subgroups
· Check for missing groups and adjust methods accordingly
An example of biased sampling would be conducting a study of how all students at a university feel about campus food, but only surveying students at the cafeteria at lunchtime. The result of the study would overrepresent students who eat on campus and underrepresent those who don’t.
An example of biased sampling in R can be seen below:-



See video on bias in sampling:- https://youtu.be/p7R3lyFvJ38
Randomisation
Ramdomisation in the sampling process is the process of selecting units from a population in such a way that every member has a known, non-zero chance of being chosen, with the choice being driven by chance and not human judgement. It is is the backbone of fair, unbiased sampling.
Ramdomisation protects a study from hidden patterns, personal preferences, and systematic distortions. When the selection is random, the sample tends to mirror the population without bias.
Ramdomisatrion matters because:-
· It reduces sampling bias
· It balances out unknown factors, such as age, income, and habits
· It makes results generalisable
Types of randomisation in sampling include:-
-
Simple random sampling, where every individual has an equal chance of being selected.
-
Systematic random sampling, where a starting point is selected and every kthg element is sampled thereafter.
-
Stratified random sampling, where the population is divided into groups and random sampling occurs within each group.
-
Cluster random sampling, where clusters are formed within a population and all of those clusters are taken or randomly sampled.
Randomisation protects the researcher from:-
· choosing easy to reach elements of a population
· choosing similar elements
· choosing elements that are available only in certain instances
· hidden patterns in the population
· human intuition, which is often biased
An example of how randomisation works is:-
If you want to sample 100 students from a university of 10,000 and stand outside the library at 10:00 am, you will oversample:-
· morning people
· library users
· people with lighter schedules
Randomisation avoids the problems cited above because students are selected by chance, not convenience.
A simple program in R, demonstrating ramdomisation, can be seen below:-



See video on randomisatrion:- https://youtu.be/Y_1moLNqga8
Understanding the difference between a parameter and a statistic?

In the field of statistics, two fundamental concepts play a crucial role in data analysis: parameters and statistics. While both terms are used to describe numerical values that summarize data, they have distinct meanings and applications. Understanding the difference between a parameter and a statistic is essential for interpreting and making inferences from data accurately.
Definition and Characteristics of a Parameter
A parameter is a numerical value that describes a characteristic of a population. The population refers to the entire group of individuals or items that are of interest in a particular study. Parameters are used to summarize data for the entire population and are often denoted by Greek letters. Some common parameters include:
-
Population Mean (μ): The average value of all data points in the population.
-
Population Variance (σ²): The measure of the spread of data points in the population.
-
Population Proportion (p): The proportion of a particular characteristic within the population.
Characteristics of Parameters:
-
Fixed Value: Parameters are fixed values that do not change because they describe the entire population.
-
Not Directly Observable: Parameters are often not directly observable because collecting data from the entire population is impractical. Instead, they are estimated using sample data.
-
True Representation: Parameters represent the true values and characteristics of the population.
Definition and Characteristics of a Statistic
A statistic is a numerical value that describes a characteristic of a sample. A sample is a smaller, manageable subset of the population selected for the purpose of conducting research. Statistics are used to summarize data for the sample and are often denoted by Latin letters. Some common statistics include:
-
Sample Mean (x̄): The average value of all data points in the sample.
-
Sample Variance (s²): The measure of the spread of data points in the sample.
-
Sample Proportion (p̂): The proportion of a particular characteristic within the sample.
Characteristics of Statistics:
-
Variable Value: Statistics can vary because they describe a sample, and different samples can yield different statistics.
-
Directly Observable: Statistics are directly observable because they are calculated from sample data.
-
Estimation of Parameters: Statistics are used to estimate the values of parameters and make inferences about the population.
Roles of Parameters and Statistics in Statistical Analysis
Parameters and statistics play distinct but complementary roles in statistical analysis:
1. Descriptive Statistics: Descriptive statistics involve summarizing and describing the main features of a dataset. Statistics such as sample mean, sample variance, and sample proportion are used to summarize the sample data.
-
Inferential Statistics: Inferential statistics involve making predictions or inferences about the population based on sample data. Statistics are used to estimate parameters and test hypotheses. For example, the sample mean (x̄) is used to estimate the population mean (μ).
-
Hypothesis Testing: In hypothesis testing, statistics are used to determine whether there is enough evidence to reject a null hypothesis. Parameters represent the assumed values for the population, while statistics provide evidence from the sample data.
Understanding sampling distributions: the backbone of inferential statistics
Sampling distributions are a fundamental concept in statistics, playing a crucial role in the field of inferential statistics. They allow researchers to make inferences about a population based on sample data. By understanding sampling distributions, one can appreciate the variability inherent in sample statistics and the accuracy of estimates made about population parameters.
Definition and Concept of Sampling Distributions
A sampling distribution is the probability distribution of a given statistic based on a large number of samples drawn from the same population. In essence, it describes the distribution of a statistic (e.g., sample mean, sample variance) that results from repeated sampling of the population. The concept of sampling distributions is rooted in the understanding that different samples from the same population can yield different statistics due to random variability.
For example, if we repeatedly draw random samples of a fixed size from a population and calculate the mean for each sample, the distribution of these sample means forms the sampling distribution of the sample mean.
Key Characteristics of Sampling Distributions
- Shape:
- The shape of a sampling distribution depends on the shape of the population distribution and the sample size. According to the Central Limit Theory, for large sample sizes, the sampling distribution of the sample mean tends to be approximately normal, regardless of the shape of the population distribution.
- Mean of Sampling Distribution:
- The mean of the sampling distribution of the sample mean (μ_x̄) is equal to the population mean (μ). This property is known as the unbiasedness of the sample mean.
- Standard Error:
- The standard error (SE) is the standard deviation of the sampling distribution of a statistic. It measures the variability of the statistic from sample to sample and is calculated as the population standard deviation (σ) divided by the square root of the sample size (n): SE = σ / √n. The standard error decreases as the sample size increases, indicating that larger samples provide more accurate estimates of the population parameter.
- Variability:
- The variability of a sampling distribution depends on the sample size and the variability of the population. Larger sample sizes result in less variability in the sampling distribution, leading to more precise estimates.
Applications of Sampling Distributions
- Estimation:
— Sampling distributions are used to estimate population parameters. For example, the sampling distribution of the sample mean is used to estimate the population mean. Confidence intervals can be constructed using the standard error to provide a range of plausible values for the parameter.


- Hypothesis Testing:
— Sampling distributions form the basis for hypothesis testing. By comparing the observed sample statistic to the sampling distribution under the null hypothesis, researchers can determine the likelihood of observing such a statistic by chance. This helps in making decisions about whether to reject the null hypothesis.




3. Central Limit Theorem (CLT):
- The Central Limit Theorem is a key concept related to sampling distributions. It states that for a sufficiently large sample size, the sampling distribution of the sample mean will be approximately normally distributed, regardless of the population distribution. This property allows for the use of normal probability models in inferential statistics.



- Comparing Sample Statistics:
— Sampling distributions allow for the comparison of sample statistics across different studies or experiments. By understanding the variability of sample statistics, researchers can assess the consistency and reliability of their findings.



See video on applications of sampling distributions:- https://youtu.be/k95k_Fl1OeQ
Importance of Sampling Distributions
Sampling distributions are important for several reasons, to include:
- Foundation of Inferential Statistics:
- Sampling distributions provide the foundation for making inferences about population parameters based on sample data. They allow researchers to quantify the uncertainty associated with sample statistics and make probabilistic statements about population characteristics.
- Understanding Variability:
- Sampling distributions help in understanding the variability inherent in sample statistics. This understanding is crucial for assessing the accuracy and precision of estimates and for making informed decisions based on data.
3. Constructing Confidence Intervals:
- Sampling distributions are used to construct confidence intervals, providing a range of plausible values for population parameters. Confidence intervals are essential for expressing the uncertainty associated with estimates.
- Enabling Hypothesis Testing:
- Sampling distributions enable hypothesis testing by providing the framework for comparing observed sample statistics to theoretical distributions. This comparison helps in determining the statistical significance of findings and drawing valid conclusions.
Some of the most common sampling distributions
There are several common sampling distributions in statistics, each with its own applications and properties. Here are some of the most widely used sampling distributions:
- Sampling Distribution of the Sample Mean:
— This distribution describes the distribution of the mean values of samples taken from a population. It is often approximated by a normal distribution, especially when the sample size is large, due to the Central Limit Theorem.


- Sampling Distribution of the Sample Proportion:
— This distribution describes the distribution of sample proportions (e.g., the proportion of successes in a series of trials). It is used in situations where we are interested in the proportion of a particular characteristic within the sample. When the sample size is large, the distribution of the sample proportion is approximately normal.


- Chi-Square Distribution:
— The chi-square distribution is used in tests of independence and goodness-of-fit tests. It describes the distribution of the sum of squared standard normal variables. It is also used in the analysis of variance (ANOVA) and in estimating population variances.


- t-Distribution:
— The t-distribution is used when estimating population parameters when the sample size is small and/or the population standard deviation is unknown. It is similar to the normal distribution but has heavier tails, which means it provides a better estimate when dealing with small sample sizes.


- F-Distribution:
— The F-distribution is used primarily in ANOVA and regression analysis. It describes the distribution of the ratio of two independent chi-square variables divided by their respective degrees of freedom.


- Binomial Distribution:
— The binomial distribution describes the distribution of the number of successes in a fixed number of independent Bernoulli trials with the same probability of success. It is widely used in situations involving binary outcomes (e.g., success/failure, yes/no).


- Poisson Distribution:
— The Poisson distribution describes the distribution of the number of events occurring in a fixed interval of time or space, given a constant mean rate of occurrence. It is used in situations where events occur randomly and independently.


- Sampling Distribution of the Sample Variance:
— This distribution describes the distribution of sample variances. It is used in inferential statistics to estimate the population variance and to conduct hypothesis tests related to variance.


These sampling distributions are foundational in the field of statistics, providing the basis for various inferential methods, including hypothesis testing, estimation, and confidence interval construction. Understanding the properties and applications of these distributions is essential for making accurate inferences about populations based on sample data.
See video on sampling distributions:- https://youtu.be/3lpje2DtrfA
Confidence intervals in inferential statistics
Confidence intervals are a fundamental concept in inferential statistics, providing a range of plausible values for an unknown population parameter based on sample data. Unlike point estimates, which offer a single value as an estimate, confidence intervals account for the inherent variability in sampling and provide a measure of uncertainty associated with the estimate.

Definition and Concept of Confidence Intervals
A confidence interval is a range of values, derived from sample data, that is likely to contain the true population parameter with a specified level of confidence. The confidence level represents the probability that the confidence interval will contain the true parameter in repeated samples. Common confidence levels include 90%, 95%, and 99%.
For example, a 95% confidence interval for the population mean (μ) suggests that if we were to take many random samples from the population and calculate the confidence interval for each sample, approximately 95% of these intervals would contain the true population mean.
Calculation of Confidence Intervals

The calculation of confidence intervals depends on the type of parameter being estimated and the distribution of the sample statistic. Here are the steps to calculate a confidence interval for the population mean (μ) when the sample size is large (n ≥ 30) or the population standard deviation (σ) is known:
- Point Estimate:
— Calculate the sample mean (x̄) as the point estimate of the population mean.

- Standard Error:
— Calculate the standard error (SE) of the sample mean. The standard error is the standard deviation of the sampling distribution of the sample mean and is given by:

- Critical Value:
— Determine the *critical value (z) corresponding to the desired confidence level. The critical value is obtained from the standard normal distribution (z-distribution) and represents the number of standard errors that correspond to the specified confidence level**.

- Margin of Error:
— Calculate the margin of error (MOE) using the formula:

5. Confidence Interval:
— Construct the confidence interval by adding and subtracting the margin of error from the sample mean:

For small sample sizes (n < 30) or when the population standard deviation is unknown, the t-distribution is used instead of the z-distribution, and the sample standard deviation (s) is used in place of the population standard deviation (σ).
A small program in R demonstrating confidence intervals can be seen below:-





See video on point estimate and confidence intervals:- https://youtu.be/D3PSnoRejsU
Interpretation of Confidence Intervals
Interpreting confidence intervals requires understanding the confidence level and the range of values provided by the interval. A confidence interval provides a range of plausible values for the unknown population parameter, taking into account the variability in sampling.
For example, suppose we have a 95% confidence interval for the population mean as (45.2, 54.8). This interval suggests that we are 95% confident that the true population mean lies between 45.2 and 54.8. It is important to note that this interpretation does not imply that there is a 95% probability that the true mean lies within this specific interval. Instead, it means that if we were to take many random samples and calculate confidence intervals for each, approximately 95% of those intervals would contain the true mean.
Importance of Confidence Intervals
Confidence intervals are important for several reasons, being:-
- Quantifying Uncertainty:
- Confidence intervals provide a measure of uncertainty associated with point estimates. They account for the variability in sampling and offer a range of plausible values for the population parameter.
2. Making Inferences:
- Confidence intervals are used to make inferences about population parameters based on sample data. They allow researchers to draw conclusions about the population with a specified level of confidence.
- Decision-Making:
- Confidence intervals inform decision-making by providing a range of values within which the true parameter is likely to lie. This information is valuable in fields such as medicine, economics, and social sciences, where decisions are based on statistical analysis.
4. Comparison of Estimates:
- Confidence intervals allow for the comparison of estimates across different studies or experiments. Overlapping confidence intervals suggest that the estimates may not be significantly different, while non-overlapping intervals indicate a potential difference.
Confidence interval practice questions:-
Here are five practice questions related to calculating confidence intervals in Python. These questions will help you apply different methods and scenarios to understand how confidence intervals work:
Practice Question 1:
Simulate a sample of 40 observations from a normal population of mean 70 and standard deviation of 10. Compute 95% confidence interval for the population mean assuming sigma is known.



Practice Question 2:
Simulate 25 observations from a normal distribution with mean of 15 and a standard deviation of 4. Compute 95% t based confidence interval for the mean.




Practice Question 3:
Simulate 300 Bernoulli trials with probability success of .4. Compute 95% confidence interval for the true proportion.


Practice Question 4:
Simulate two independent samples: a: n=35, mean=50, sd=8; b: n=40, mean = 54, sd=9. Compute 95% confidence interval for the difference in means (a-b).



Practice Question 5:
Simulate 60 observations from a skewed exponential distribution. Use bootstrap resampling to compute 95% confidence interval for the median. Bootstrap resampling is a technique where you repeatedly sample with replacement from your observed data to estimate the variability of a statistic.



See video on confidence intervals:- https://youtu.be/625Y10GBHMs
Bootstrapping
Bootstrapping is a resampling based method that lets the researcher estimate how much a statistic (such as mean, median, regression coefficient etc) would vary if he could repeatedly collect new samples from the population. The core idea of bootstrapping is to treat the observed data as if it were the population, then repeatedly sample from the sample with replacement to mimic the process of drawing many new datasets.
Bootstrapping builds an empirical sampling by resampling the data thousands of times, allowing the researcher to estimate standard errors, confidence intervals, and hypothesis tests without strong parametric assumptions.
Bootstrapping is a powerful technique because:-
· it doesn’t assume normality or other strict distributional forms
· it works for almost any statistic, even complicated ones
· it is conceptionally intuitive because a statistic can be computed thousands of times
The procedure for bootstrapping is as follows:-
-
Start with the original dataset of size n.
-
Draw a bootstrap sample by randomly selecting n observations with replacement.
-
Compute the statistic of interest on that sample (an example being the mean).
-
Repeat step 3 many time, such as 1,000 to 10,000 times.
-
The distribution of the resulting bootstrap statistics approximates the sampling distribution.
Bootstrapping can be used to:-
· Estimate standard errors because the spread of the distribution gives a natural estimate of variability.
· Build confidence intervals.
· Perform hypothesis tests. By comparing the observed statistic to the bootstrap distribution, p-values can be computed without relying on theoretical distributions.
Bootstrapping relies on the idea that the sample is a reasonable stand-in for the population.
Bootstrapping is a good technique to use when the researcher desires:-
· Non-parametric inference
· Confidence intervals for medians, percentiles, or regression coefficients
· Robust inference for skewed or irregular data
· A simple, intuitive alternative to classical formulas
Bootstrapping the mean using the sample() function can be seen below:-



Bootstrapping the mean using the replicate() function can be seen below:-



Below is the code in R to bootstrap a CI for a real dataset:-



Comparing analytical (theoretical) confidence interval with a bootstrap confidence interval is one of the best ways to show how sampling differs from classical inference.
Below is a comparison of analytic versus bootstrap CI in R:-




See video on bootstrapping:- https://youtu.be/11G_Mqmpubo
Hypothesis testing
Hypothesis testing is a fundamental concept in statistics that enables researchers to make inferences about populations based on sample data. It involves formulating a null hypothesis (H0) and an alternative hypothesis (Ha or H1), and then using statistical methods to determine whether the observed data provides sufficient evidence to reject the null hypothesis in favour of the alternative hypothesis.
Key Concepts in Hypothesis Testing
-
Null Hypothesis (H0): The null hypothesis represents the default or status quo assumption about a population parameter. It is a statement that there is no effect or no difference, and it serves as the basis for the test.
-
Alternative Hypothesis (Ha or H1): The alternative hypothesis represents a statement that contradicts the null hypothesis. It suggests the presence of an effect or a difference.
-
Test Statistic: The test statistic is a standardized value calculated from sample data. It is used to determine the likelihood of observing the sample data under the null hypothesis.
-
P-Value: The p-value is the probability of obtaining a test statistic at least as extreme as the one observed, assuming the null hypothesis is true. The p-value is expressed as a percentage. A small p-value indicates strong evidence against the null hypothesis.
-
Significance Level (alpha): The significance level is a threshold chosen by the researcher, typically set at 0.05 or 0.01. If the p-value is less than (alpha), the null hypothesis is rejected in favour of the alternate hypothesis.
-
Type I and Type II Errors:
- Type I Error: Rejecting the null hypothesis when it is true (false positive).
— Type II Error: Failing to reject the null hypothesis when it is false (false negative).

A hypothesis test using a t-test can be seen below:-




A hypothesis test for a chi square test can be seen below:-




R’s prop.test() function performs a hypothesis test for one or more population proportions, using chi square test for proportions. This function is used when the researcher wants to compare proportions rather than means.
Aa hypothesis test using the prop.test() function can be seen below:-




A manual permutation test is a hypothesis testing method where the test statistic is computed for every possible rearrangement (permutation) by hand (or with a simple code) to build the sampling distribution without relying on normality, t-tests, or any parametric assumptions. It is one of the most intuitive, assumption-free ways to test whether two groups differ.
A manual permutation test using R’s sample() function can be seen below:-




A sample hypothesis test report using a t-test can be seen below:-



See video on hypothesis testing in R:- https://youtu.be/NtF6XTMgOAc
Practice hypothesis tests
Practice Hypothesis Test 1:
A factory claims the mean weight of its cereal boxes is 500 grams. Collect a sample to check this:
H0 = 500 grams, Ha <> 500 grams.




Practice Hypothesis Test 2:
Compare test scores of students taught with method A and method B.
H0: mean A = mean B, Ha: mean A <> mean B




Practice Hypothesis Test 3:
A fitness program measures participants resting heart rate before and after eight weeks.
H0: before mean = after mean, Ha: before mean <> after mean




Practice Hypothesis Test 4:
Test whether gender is independent of product preference.
H0: gender and preference are independent, Ha: gender and preference are associated



Practice Hypothesis Test 5:
Compare mean plant growth across three fertiliser types.
H0: mean 1 = mean 2 = mean 3, H1: at least one mean differs



See video on hypothesis tests:- https://youtu.be/9xu8XUrF7oU
메타데이터
- post_id
- 7415876e9e8d
- slug
- explore-statistics-with-r-inferential-statistics-7415876e9e8d
- url
- https://medium.com/@tracyrenee61/explore-statistics-with-r-inferential-statistics-7415876e9e8d
- canonical_url
- https://medium.com/@tracyrenee61/explore-statistics-with-r-inferential-statistics-7415876e9e8d
- author_url
- https://medium.com/@tracyrenee61
- status
- ok
- fetched_at
- 2026-07-31 18:43:46