Simple Linear Regression quarto

Quarto

Quarto enables you to weave together content and executable code into a finished document. To learn more about Quarto see https://quarto.org.

Running Code

When you click the Render button a document will be generated that includes both content and the output of embedded code. You can embed code like this:

1. Draw a scatter plot of Y vs X:

library(readr)
gpa <- read_csv("C:/Users/korra/Downloads/GPA.csv",col_names = TRUE)
Rows: 120 Columns: 2
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (2): Y, X

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
#head(gpa)

# Scatterplot
plot(gpa$X, gpa$Y, xlab = "ACT Scores", ylab = "GPA", main = "Scatterplot of GPA vs ACT Scores")

2. Fit a regression model and write down the estimated regression function:

# Fit a linear regression model
model<-lm(Y~X,data=gpa)

# Print the estimated regression function
coefficients <- coef(model)
cat("Regression function: Y =", round(coefficients[2], 4), "* X +", round(coefficients[1], 4), "\n")
Regression function: Y = 0.0388 * X + 2.114 

\[ Y = 0.0388 * X + 2.114\]

3. Plot the estimated regression line and the data

model<-lm(Y~X,data=gpa)
summary(model)$coefficients
              Estimate Std. Error  t value     Pr(>|t|)
(Intercept) 2.11404929 0.32089483 6.587982 1.304450e-09
X           0.03882713 0.01277302 3.039777 2.916604e-03
# Scatterplot
plot(gpa$X, gpa$Y, xlab = "ACT Scores", ylab = "GPA", main = "Scatterplot of GPA vs ACT Scores")
points(gpa$X,model$fit, type="l", col="red")

4. Point estimate of the change in the mean response when the entrance test score increases by one point \[\beta_1 = 0.0388\] 5. Obtain a 99 percent confidence interval for β1

conf_int <- confint(model, level = 0.99)
cat("99% Confidence Interval for β1:", round(conf_int[2, ], 4), "\n")
99% Confidence Interval for β1: 0.0054 0.0723 
cat(" The confidence interval does", ifelse(0 >= conf_int[2, 1] & 0 <= conf_int[2, 2], "include", "not include"), "zero.\n")
 The confidence interval does not include zero.

This means we are 99% confident that for an additional ACT Score, the GPA increases by between 0.0054 and 0.0723 points.

6. Test for linear association between student’s ACT score and GPA at a significance level of 0.05