Objective:

This lab assignment aims to reinforce your understanding of descriptive statistics, calculating probabilities, and identifying sample spaces. You will apply these concepts to practical problems using R.

Homework Exercises:

Exercise 1: Analyzing Descriptive Statistics

  • Task: Given a dataset of reaction times, calculate the mean, median, mode, variance, standard deviation, and identify any outliers.

  • Dataset: Use the following reaction times (in milliseconds) for the analysis:

reaction_times <- c(250, 340, 295, 305, 285, 330, 365, 300, 310, 290, 295, 285, 360, 370, 275, 325, 335, 350, 280, 290)
  • Calculations:
# Calculate mean
mean_value <- mean(reaction_times)
print(paste("Mean:", mean_value))
## [1] "Mean: 311.75"
# Calculate median
median_value <- median(reaction_times)
print(paste("Median:", median_value))
## [1] "Median: 302.5"
# Calculate mode
get_mode <- function(x) {
  uniqv <- unique(x)
  uniqv[which.max(tabulate(match(x, uniqv)))]
}
mode_value <- get_mode(reaction_times)
print(paste("Mode:", mode_value))
## [1] "Mode: 295"
# Calculate variance
variance_value <- var(reaction_times)
print(paste("Variance:", variance_value))
## [1] "Variance: 1113.88157894737"
# Calculate standard deviation
sd_value <- sd(reaction_times)
print(paste("Standard Deviation:", sd_value))
## [1] "Standard Deviation: 33.3748644783371"

Exercise 2: Identifying Outliers

# Adding an outlier
reaction_times_outlier <- c(reaction_times, 900)

# Calculate quartiles and other statistics
Q1 <- quantile(reaction_times_outlier, 0.25)
Q3 <- quantile(reaction_times_outlier, 0.75)
IQR_value <- IQR(reaction_times_outlier)
lower_bound <- Q1 - 1.5 * IQR_value
upper_bound <- Q3 + 1.5 * IQR_value
outliers <- reaction_times_outlier[reaction_times_outlier < lower_bound | reaction_times_outlier > upper_bound]

print(paste("Lower Bound:", lower_bound))
## [1] "Lower Bound: 215"
print(paste("Upper Bound:", upper_bound))
## [1] "Upper Bound: 415"
print("Outliers:")
## [1] "Outliers:"
print(outliers)
## [1] 900

Exercise 3: Boxplot

# Create a boxplot
boxplot(reaction_times_outlier, 
        main = "Reaction Times with Labeled Quantiles",
        ylab = "Time (ms)",
        col = "lightblue",
        outline = TRUE)

Exercise 4: Probability Calculations

# Parameters
mean <- 300
sd <- 50

# Probability of a reaction time less than 250 ms
prob_less_250 <- pnorm(250, mean = mean, sd = sd)
print(paste("P(X < 250):", prob_less_250))
## [1] "P(X < 250): 0.158655253931457"
# Probability of a reaction time between 250 ms and 350 ms
prob_between_250_350 <- pnorm(350, mean = mean, sd = sd) - pnorm(250, mean = mean, sd = sd)
print(paste("P(250 < X < 350):", prob_between_250_350))
## [1] "P(250 < X < 350): 0.682689492137086"
# Probability of a reaction time more than 400 ms
prob_more_400 <- 1 - pnorm(400, mean = mean, sd = sd)
print(paste("P(X > 400):", prob_more_400))
## [1] "P(X > 400): 0.0227501319481792"

Exercise 5: t-Distribution Probabilities

# Degrees of freedom
df <- 7  # for n = 8, df = n - 1

# Probability of a t-score less than 2
prob_t_less_2 <- pt(2, df = df)
print(paste("P(T < 2):", prob_t_less_2))
## [1] "P(T < 2): 0.957190335718512"
# Probability of a t-score between -1 and 1
prob_t_between_neg1_1 <- pt(1, df = df) - pt(-1, df = df)
print(paste("P(-1 < T < 1):", prob_t_between_neg1_1))
## [1] "P(-1 < T < 1): 0.649383337179793"

This completes the probability and descriptive statistics exercises for this lab assignment.