EZ

Eduzan

Learning Hub

Eduzan
Eduzan / Data Science

Statistical Analysis

In data science and statistics, understanding probability, distributions, hypothesis testing, correlation, regression, and statistical significance is essential for making informed decisions and interpreting data correctly.

Probability is the measure of the likelihood that an event will occur. It ranges from 0 (the event will not occur) to 1 (the event will certainly occur).

Types of Probability:

  • Classical Probability: Based on equally likely outcomes (e.g., rolling a die).
  • Empirical Probability: Based on observed data (e.g., the probability of rain based on historical data).
  • Subjective Probability: Based on personal judgment or experience.

Rules of Probability:

  • Addition Rule: P(A or B)=P(A)+P(B)−P(A and B)P(A \text{ or } B) = P(A) + P(B) – P(A \text{ and } B)P(A or B)=P(A)+P(B)−P(A and B)
  • Multiplication Rule: P(A and B)=P(A)×P(B∣A)P(A \text{ and } B) = P(A) \times P(B|A)P(A and B)=P(A)×P(B∣A) for dependent events, or P(A)×P(B)P(A) \times P(B)P(A)×P(B) for independent events.
  • Complementary Rule: P(not A)=1−P(A)P(\text{not } A) = 1 – P(A)P(not A)=1−P(A)

Distributions

A probability distribution describes how the values of a random variable are distributed. It tells us the likelihood of different outcomes.

Types of Distributions:

Discrete Distributions: Concerned with outcomes that are discrete (countable).

  • Binomial Distribution: Models the number of successes in a fixed number of independent Bernoulli trials.
  • Poisson Distribution: Models the number of events occurring in a fixed interval of time or space.

Continuous Distributions: Concerned with outcomes that are continuous (can take any value within a range).

  • Normal Distribution: A symmetric, bell-shaped distribution where most of the data falls around the mean.
  • Exponential Distribution: Models the time between events in a Poisson process.
  • Uniform Distribution: All outcomes are equally likely within a given range.
    •  

Example in Python (Normal Distribution):

import numpy as np
import matplotlib.pyplot as plt

# Generate data from a normal distribution
data = np.random.normal(loc=0, scale=1, size=1000)

# Plotting the distribution
plt.hist(data, bins=30, density=True, alpha=0.6, color='g')
plt.title('Normal Distribution')
plt.xlabel('Value')
plt.ylabel('Frequency')
plt.show()

Example in R (Binomial Distribution):

# Generate data from a binomial distribution
data <- rbinom(1000, size=10, prob=0.5)

# Plotting the distribution
hist(data, breaks=10, col="lightblue", main="Binomial Distribution", xlab="Number of Successes")

Example in R:

# Example dataset
scores <- c(70, 85, 78, 92, 88, 75, 60, 95, 83, 72)
hours_studied <- c(2, 4, 3, 5, 4.5, 3, 1.5, 6, 4, 2.5)

# Histogram
hist(scores, breaks=5, main="Histogram of Scores", xlab="Scores", col="blue", border="black")

# Box Plot
boxplot(scores, main="Box Plot of Scores", ylab="Scores")

# Scatter Plot
plot(hours_studied, scores, main="Scatter Plot of Hours Studied vs. Scores", xlab="Hours Studied", ylab="Scores", pch=19, col="red")
End of lesson.