Use this file to write your answer to Assignment 1. You will need to knit it to PDF and then submit this PDF to Canvas.
Insert as many R code chunks as needed, using:
# copy and paste
Answer: (b) FALSE
Explanation: The problem or research question determines the course of the hypothesis test. Depending on whether we are testing for a specific value, less than a specific value, or more than a specified value, hypothesis tests can be one-sided (either left- or right-tailed) or two-sided. It is not possible to generalise the percentage of two-sided cases to a set value, such as 56%. It changes according to the particular idea and study’s setting.
Answer: (b) FALSE
Explanation: There is insufficient data to reject the null hypothesis when the p-value is higher than the significance level, or alpha. It is not statistically significant as a result. The null hypothesis cannot be rejected when the p-value is greater than 0.05, indicating that the alternative hypothesis is not sufficiently supported by the available data.
Answer: (c) HO: p = 0.13 vs Ha: p > 0.13.
Explanation: According to the null hypothesis (HO) (p = 0.13), the percentage of male students who smoke is equal to the recognised figure of 13%. Since the goal of the investigation is to determine whether the percentage of smokers is higher than previous research indicates, the alternative hypothesis (Ha) is that the proportion is larger than 13% (p > 0.13).
Conclusion: We reject the null hypothesis that there are 13% of male students who smoke regularly since the p-value of 0.02 is less than the significance level of 0.05. This offers compelling evidence that the percentage of male students who smoke regularly is greater than 13%.
Answer: (a) TRUE
Explanation: Sample statistics, like the sample mean or proportion, are used to calculate confidence intervals. In order to estimate the genuine population parameter, they present a range of tenable values together with a confidence level (such as 95%), indicating that the true value is within this range.
Answer: (b) FALSE
Explanation: The precision of our estimate decreases as the breadth of the confidence interval increases, e.g., from 90% to 95%, as the confidence level increases. Although a broader interval results in less precision, a greater confidence level increases the likelihood that the interval contains the correct population parameter.
Answer: (a) Confidence intervals give a range of plausible values which may include an unknown population parameter.
Explanation: Based on sample statistics, confidence intervals offer a range of reasonable values for an unknown population parameter. An estimate of the parameter and a multiple of the estimate’s standard deviation, which is usually obtained from the standard error, are used to generate this interval. Neither a narrower interval nor a greater confidence level correspond to a range of sample values in confidence intervals.
Answer: (c) the variables are not correlated, so r = 0.
Explanation: The statistical relationship between two variables is known as correlation. When two variables have a positive correlation, it indicates that the values of the two tend to rise together as one variable’s value does. On the other hand, a negative correlation means that the value of one variable tends to drop as the value of the other increases. When there is no correlation, the two variables’ changes do not follow a dependable pattern.
Answer: (b) coffee salesi = β0 + β1 · temperaturei + εi εi ∼ N(0, σ²)
Explanation: With “temperature” serving as the independent variable (predictor variable) and “coffee sales” serving as the dependent variable (response variable), the regression model attempts to explain “coffee sales” in terms of “temperature.” As a result, coffee salesi = β0 + β1 · temperaturei + ϵi ϵi ∼ N(0, σ²) is the suitable model. This model uses β0 for the intercept, β1 for the slope, and εi for the error term (which is assumed to be normally distributed with mean 0 and variance σ²) to evaluate the relationship between “coffee sales” and “temperature.”
Answer: (b) The sample mean.
Explanation: Since confidence intervals are built around the sample mean to estimate the population mean, the sample mean (point estimate) is the midpoint of a confidence interval for the population mean. Based on the available data, the sample mean provides the most accurate estimate of the population mean.
# copy and paste
install.packages(c("dplyr", "crayon"))
library(dplyr)
## Question 2 Data set ##
# Step 1. Download the file 'Question2.csv' and save in your preferred folder on disk.
# Step 2. Enter below the location path of the file 'Question2.csv'
# For example:
dataQ2 <- read.csv("C:/Users/pvz12/Downloads/Question2.csv")
# Replace above "C:/Users/pvz12/Downloads/Question2.csv" with the correct location path, from your computer.
# Don't forget to add the file name at the end.
# Also, use / and not \ .
class(dataQ2)
dataQ2
# Load the dataset
dataQ2 <- read.csv("C:/Users/pvz12/Downloads/Question2.csv")
# Check the column names in the data frame
print(colnames(dataQ2))
# Calculate BMI with error handling
dataQ2 <- dataQ2 %>%
mutate(
bmi = if_else(
weight > 0 & Height > 0,
weight / (Height ^ 2),
NA_real_
)
)
# Select variables for correlation analysis
vars <- dataQ2 %>%
select(Age, weight, runtime, Height, bmi)
# Calculate the correlation matrix
correlation_matrix <- cor(vars, use = "pairwise.complete.obs")
# Print the correlation matrix
print(correlation_matrix)
output of correlation matrix:
# copy and paste
Age weight runtime Height bmi
Age 1.00000000 -0.03878961 0.23862614 -0.06721659 0.01685263
weight -0.03878961 1.00000000 -0.17133041 0.31944009 0.91453566
runtime 0.23862614 -0.17133041 1.00000000 -0.47193283 0.02626464
Height -0.06721659 0.31944009 -0.47193283 1.00000000 -0.08444221
bmi 0.01685263 0.91453566 0.02626464 -0.08444221 1.00000000
Discussion: Given that BMI is calculated from height and weight, the correlation matrix shows a high correlation (0.9145) between weight and BMI. This may indicate that the two variables are collinear. Taller people might finish the 1.5-mile run faster, according to the moderate inverse correlation (-0.4719) between runtime and height; however, this link is not strong enough to cause multicollinearity issues. Minimal collinearity in such characteristics is suggested by low correlations involving runtime and low correlations between age and other explanatory variables. Generally, the main possible collinearity problem is the strong correlation between weight and BMI; selecting one variable in a regression model over the other may assist reduce collinearity and prevent redundancy.
# copy and paste
# Load the dataset
dataQ2 <- read.csv("C:/Users/pvz12/Downloads/Question2.csv")
# Fit the multiple regression model
model <- lm(Oxygen ~ Age + runtime + bmi, data = dataQ2)
# Print the summary of the model
summary(model)
output:
# copy and paste
Call:
lm(formula = Oxygen ~ Age + runtime + bmi, data = dataQ2)
Residuals:
Min 1Q Median 3Q Max
-8.628 -1.502 0.192 1.687 6.075
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 90.99678 7.83258 11.618 8.56e-12 ***
Age -0.14990 0.12125 -1.236 0.227
runtime -2.94548 0.43190 -6.820 3.08e-07 ***
bmi -0.09829 0.15580 -0.631 0.534
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 3.321 on 26 degrees of freedom
Multiple R-squared: 0.6825, Adjusted R-squared: 0.6459
F-statistic: 18.63 on 3 and 26 DF, p-value: 1.17e-06
Age coefficient: Keeping all other factors equal, the computed age coefficient shows how a one-year increase in age affects the oxygen intake rate (aerobic fitness). Depending on the age, aerobic fitness either rises or falls, as indicated by a positive or negative coefficient.
Body mass index (BMI) coefficient: Keeping all other factors equal, the computed BMI coefficient shows how a one-unit increase in BMI affects the oxygen intake rate. Once more, a positive or negative coefficient indicates whether aerobic fitness rises or falls as bmi rises.
The adjusted R-squared and other model diagnostics, such as the R-squared value, should also be examined. Greater R-squared values signify an improved model-data fit.
R-squared: This statistic calculates the percentage of the dependent variable’s variance that the model can account for. A high fit is indicated by a high R-squared value.
Adjusted R-squared: This metric takes the number of predictors in the model into consideration. When the adjusted R-squared value is high, the model is doing well when taking the number of predictors into account.
Important predictors: P-values can be used to identify significant predictors. Low p-values (often less than 0.05) indicate statistical significance, making the predictors crucial to the model. ## (e) I agree that the runtime—the amount of time it takes to run 1.5 miles—is a significant predictor of oxygen use based on the p-values. For age and BMI, on the other hand, I disagree with the statement because the model’s p-values show that they are not statistically significant predictors of oxygen consumption.
Therefore because runtime is a strong predictor of oxygen consumption but age and BMI are not in this model, I can only partially agree with the statement in red highlighted above.
We have scores for the same group of 11 students in two subject areas (algebra and arithmetic) based on the data set that was provided. This suggests a paired sample scenario because the scores for the two subject areas are derived from the same students. As a result, a paired t-test is the best suitable hypothesis test for this collection of data. This test compares the means of two related groups to see if there is a significant difference between them (in this case, the scores from the two subject areas for the same set of students).
# copy and paste
# Load the data set
alg_arith_df <- data.frame(
"student_id" = c(4378, 2027, 2038, 2282, 2455, 2898, 3331, 4027, 4039, 2894, 2904),
"algebra_score" = c(88.2, 89.4, 96.7, 74.06, 82.61, 70.1, 78.98, 78, 75.65, 68.27, 86),
"arithmetic_score" = c(76.3, 74.2, 71.7, 89, 81.2, 91.4, 78.6, 71.14, 85, 74.41, 83.1)
)
# Show the first 10 rows of the data set
head(alg_arith_df, 10)
Output of first 10 rows of data set:
# copy and paste
student_id algebra_score arithmetic_score
1 4378 88.20 76.30
2 2027 89.40 74.20
3 2038 96.70 71.70
4 2282 74.06 89.00
5 2455 82.61 81.20
6 2898 70.10 91.40
7 3331 78.98 78.60
8 4027 78.00 71.14
9 4039 75.65 85.00
10 2894 68.27 74.41
Null hypothesis (H0): The mean test scores for the entire class do not differ between Arithmetic and Algebra. This can be stated symbolically as μ arithmetic = μ algebra.
Alternative Hypothesis (Ha): The average exam scores for the entire class differ between Arithmetic and Algebra. This can be stated symbolically as μ arithmetic ≠ μ algebra.
# copy and paste
# Perform the paired t-test
t_test_result <- t.test(alg_arith_df$arithmetic_score, alg_arith_df$algebra_score, paired = TRUE, conf.level = 0.95)
# Output the results
t_test_result
T test output results:
# copy and paste
data: alg_arith_df$arithmetic_score and alg_arith_df$algebra_score
t = -0.26464, df = 10, p-value = 0.7967
alternative hypothesis: true mean difference is not equal to 0
95 percent confidence interval:
-10.207267 8.039994
sample estimates:
mean difference
-1.083636
Conclusion: We note the test statistic and p-value in light of the paired t-test results. We reject the null hypothesis in the event that the p-value is less than 0.05. This would imply that the average test results for Arithmetic and Algebra for the entire class differ significantly.
END OF ASSIGNMENT 1