Haiding Luo
2023 11 27
1.Pick any two quantitative variables from a data set that interests you. If you are at a loss, look at the internal R datasets
Links to an external site. in base R and choose any. EG df <- cars
library(ggplot2)
Lebron <- read.csv("C:/Users/pokem/OneDrive/文档/lebron_playoffs.csv")
y <- Lebron$pts
x <- Lebron$three
model <- lm(y ~ x, data = Lebron)
summary(model)
##
## Call:
## lm(formula = y ~ x, data = Lebron)
##
## Residuals:
## Min 1Q Median 3Q Max
## -20.2134 -5.2134 -0.4116 4.7866 20.4849
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 24.5151 0.6819 35.954 < 2e-16 ***
## x 2.6982 0.3223 8.373 3.61e-15 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 7.24 on 258 degrees of freedom
## Multiple R-squared: 0.2137, Adjusted R-squared: 0.2106
## F-statistic: 70.11 on 1 and 258 DF, p-value: 3.614e-15
print(model)
##
## Call:
## lm(formula = y ~ x, data = Lebron)
##
## Coefficients:
## (Intercept) x
## 24.515 2.698
The intercept value of 24 means that when the independent variable x is zero, the predicted value of the dependent variable y is 24. If the intercept is 24, it implies that when the independent variable is zero, the predicted value of the dependent variable is 24.
3.If I want to study the relationship between a basketball player’s scoring and the number of three-point shots made in a game, “PTS” would be the dependent variable, as I am interested in understanding how scoring varies with the change in the number of three-point shots. The independent variable, in this case, would be the number of three-point shots made.
4.
cov1 <- cov(x, y)
var1 <- var(x)
a <- cov1/ var1
a
## [1] 2.698226
plot(x, y, main = "Three-pointer and total points", xlab = "Three point shot made", ylab = "total points")
abline(model, col = 'red')
5.A positive slope indicates a positive correlation between the dependent variable yand the independent variable x. When the independent variable x increases, the dependent variable y also increases accordingly.