## Secrets of successful data analysis - Sykalo Eugene 2023

# Inferential Statistics - Explanation of inferential statistics and hypothesis testing

Data Analysis Tools and Techniques

## Introduction to Inferential Statistics

Inferential statistics is a branch of statistics that deals with making inferences or conclusions about a population based on a sample of data from that population. The main purpose of inferential statistics is to draw conclusions about an entire population based on a representative sample of that population.

There are two main types of inferential statistics: estimation and hypothesis testing. Estimation involves using sample data to estimate population parameters, such as mean, variance, or proportion. Hypothesis testing involves using sample data to test a hypothesis about a population parameter.

Inferential statistics is important because it allows researchers to make generalizations about a population based on a sample of data. This is useful in many fields, such as medicine, psychology, and business, where it is often impractical or impossible to collect data from an entire population.

Inferential statistics is based on probability theory, which allows researchers to quantify the degree of uncertainty associated with their conclusions. This uncertainty is expressed in terms of p-values, which indicate the probability of obtaining a sample result as extreme or more extreme than the observed result, assuming that the null hypothesis is true.

Inferential statistics also requires researchers to make assumptions about the data, such as the distribution of the data and the independence of the observations. These assumptions must be carefully considered when choosing an appropriate inferential statistic and interpreting the results.

## Hypothesis Testing

Hypothesis testing is a statistical method that is used to determine whether a hypothesis about a population parameter is supported by the sample data. It involves comparing the sample data to what would be expected if the null hypothesis were true.

### Definition of Hypothesis Testing

A hypothesis is a statement about a population parameter, such as the population mean or proportion. Hypothesis testing involves comparing the sample data to the null hypothesis, which is a statement that there is no significant difference between the sample and the population.

### Steps Involved in Hypothesis Testing

Hypothesis testing involves several steps:

- State the null hypothesis and the alternative hypothesis. The null hypothesis is the hypothesis that there is no significant difference between the sample and the population, while the alternative hypothesis is the hypothesis that there is a significant difference.
- Determine the appropriate test statistic and the corresponding distribution. The test statistic is a measure of how far the sample data deviates from what would be expected if the null hypothesis were true.
- Calculate the p-value. The p-value is the probability of obtaining a sample result as extreme or more extreme than the observed result, assuming that the null hypothesis is true.
- Compare the p-value to the level of significance. The level of significance is the probability of rejecting the null hypothesis when it is actually true. If the p-value is less than the level of significance, then the null hypothesis is rejected.
- Interpret the results. If the null hypothesis is rejected, then the alternative hypothesis is accepted. This means that there is a significant difference between the sample and the population.

### Types of Hypothesis Testing

There are several types of hypothesis testing, including:

- One-sample t-test: used to test whether the sample mean is significantly different from a known population mean
- Two-sample t-test: used to test whether the means of two independent samples are significantly different from each other
- Paired t-test: used to test whether the means of two dependent samples are significantly different from each other
- One-way ANOVA: used to test whether the means of three or more independent samples are significantly different from each other
- Two-way ANOVA: used to test whether the means of two or more independent variables are significantly different from each other

### Common Errors in Hypothesis Testing

There are two types of errors that can occur in hypothesis testing:

- Type I error: rejecting the null hypothesis when it is actually true
- Type II error: failing to reject the null hypothesis when it is actually false

The level of significance and the power of the test can be adjusted to minimize the risk of these errors.

## Confidence Intervals

A confidence interval is a range of values that is likely to contain the true population parameter with a certain degree of confidence. It is calculated from the sample data and is used to estimate the range of values that the population parameter could take.

### Definition of Confidence Intervals

A confidence interval is a range of values that is likely to contain the true population parameter with a certain degree of confidence. The degree of confidence is expressed as a percentage, such as 95% or 99%.

### Importance of Confidence Intervals

Confidence intervals are important because they allow researchers to estimate the range of values that the population parameter could take with a certain degree of confidence. This is useful when the population parameter cannot be measured directly, such as the population mean or proportion.

Confidence intervals also allow researchers to compare the results of different studies and to determine whether the results are statistically significant. A confidence interval that does not overlap with a null value indicates that the results are statistically significant.

### Calculation of Confidence Intervals

Confidence intervals are calculated from the sample data using a formula that takes into account the sample size, the standard deviation of the sample, and the degree of confidence. The formula for a confidence interval for the population mean is:

```
CI = X ± Z * (SD / sqrt(n))
```

where CI is the confidence interval, X is the sample mean, Z is the z-score corresponding to the degree of confidence, SD is the standard deviation of the sample, and n is the sample size.

### Interpretation of Confidence Intervals

A confidence interval can be interpreted as follows: if the same experiment were repeated many times and a confidence interval were calculated for each experiment, then a certain percentage of those confidence intervals would contain the true population parameter.

For example, if a 95% confidence interval for the population mean is calculated from a sample of data, then it can be interpreted as follows: if the same experiment were repeated many times and a 95% confidence interval were calculated for each experiment, then 95% of those confidence intervals would contain the true population mean.

## Comparing Means and Proportions

### Comparison of Means

When comparing means, we are interested in whether there is a significant difference between the means of two or more groups. There are several statistical tests that can be used to compare means, depending on the type of data and the number of groups being compared.

### Two-sample t-test

The two-sample t-test is used to compare the means of two independent samples. It assumes that the data are normally distributed and that the variances of the two samples are equal. The test statistic is calculated as follows:

```
t = (x1 - x2) / (s * sqrt(1/n1 + 1/n2))
```

where x1 and x2 are the sample means, s is the pooled standard deviation, n1 and n2 are the sample sizes.

If the absolute value of the t-statistic is greater than the critical value from the t-distribution with n1 + n2 - 2 degrees of freedom and the chosen level of significance, then we reject the null hypothesis of equal means in favor of the alternative hypothesis that the means are not equal.

### Paired t-test

The paired t-test is used to compare the means of two dependent samples, such as pre-test and post-test data. It assumes that the differences between the pairs of observations are normally distributed. The test statistic is calculated as follows:

```
t = d / (s / sqrt(n))
```

where d is the mean difference between the pairs of observations, s is the standard deviation of the differences, and n is the number of pairs.

If the absolute value of the t-statistic is greater than the critical value from the t-distribution with n - 1 degrees of freedom and the chosen level of significance, then we reject the null hypothesis of equal means in favor of the alternative hypothesis that the means are not equal.

### One-way ANOVA

The one-way ANOVA is used to compare the means of three or more independent samples. It assumes that the data are normally distributed and that the variances of the groups are equal. The test statistic is calculated as follows:

```
F = (SSB / (k - 1)) / (SSW / (n - k))
```

where SSB is the sum of squares between groups, SSW is the sum of squares within groups, k is the number of groups, and n is the total number of observations.

If the calculated F-statistic is greater than the critical value from the F-distribution with k - 1 and n - k degrees of freedom and the chosen level of significance, then we reject the null hypothesis of equal means in favor of the alternative hypothesis that at least one group mean is different from the others.

### Comparison of Proportions

When comparing proportions, we are interested in whether there is a significant difference between the proportions of two or more groups. There are several statistical tests that can be used to compare proportions, depending on the type of data and the number of groups being compared.

### Chi-square test

The chi-square test is used to compare the proportions of two or more groups. It assumes that the data are categorical and that the expected frequencies are greater than 5. The test statistic is calculated as follows:

```
chi-square = sum((O - E)^2 / E)
```

where O is the observed frequency and E is the expected frequency.

If the calculated chi-square statistic is greater than the critical value from the chi-square distribution with (r - 1) * (c - 1) degrees of freedom and the chosen level of significance, then we reject the null hypothesis of equal proportions in favor of the alternative hypothesis that at least one group proportion is different from the others.

### Fisher's exact test

Fisher's exact test is used to compare the proportions of two groups when the sample size is small or when the expected frequencies are less than 5. It assumes that the data are categorical. The test statistic is calculated as follows:

```
p-value = (x! * y! * (n - x)! * (n - y)!) / (n! * a! * b! * c! * d!)
```

where n is the total sample size, x is the number of successes in group 1, y is the number of successes in group 2, a is the number of observations in group 1 that are not successes, b is the number of observations in group 2 that are not successes, c is the number of observations that are successes but not in group 1, and d is the number of observations that are successes but not in group 2.

If the calculated p-value is less than the chosen level of significance, then we reject the null hypothesis of equal proportions in favor of the alternative hypothesis that the proportions are not equal.

## ANOVA

ANOVA (Analysis of Variance) is a statistical method used to test for differences between the means of three or more groups. It is often used in experimental research to compare the effects of different treatments or interventions on a dependent variable.

### Definition of ANOVA

ANOVA is a statistical method that tests for differences between the means of three or more groups. It does this by comparing the variability between the groups to the variability within the groups. If the variability between the groups is greater than the variability within the groups, then we can conclude that there is a significant difference between the means of the groups.

### Types of ANOVA

There are several types of ANOVA, including:

- One-way ANOVA: used to test for differences between the means of three or more independent groups
- Two-way ANOVA: used to test for differences between the means of two or more independent variables
- Repeated measures ANOVA: used to test for differences between the means of three or more dependent groups

### Assumptions of ANOVA

ANOVA makes several assumptions about the data, including:

- Normality: the data are normally distributed
- Homogeneity of variances: the variances of the groups are equal
- Independence: the observations are independent of each other

If these assumptions are not met, then the results of the ANOVA may not be valid.

### Interpretation of ANOVA results

The results of an ANOVA are typically reported in terms of an F-statistic and a p-value. The F-statistic is a measure of the variability between the groups relative to the variability within the groups. The p-value is the probability of obtaining an F-statistic as extreme or more extreme than the observed F-statistic, assuming that the null hypothesis is true.

If the p-value is less than the chosen level of significance (usually 0.05), then we reject the null hypothesis of equal means in favor of the alternative hypothesis that at least one group mean is different from the others. If the p-value is greater than the chosen level of significance, then we fail to reject the null hypothesis.