Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

R Console Page 1

> # Given data


> xi <- c(65, 67, 71, 71, 66, 75, 67, 70, 71, 69, 69)
> yi <- c(175, 133, 185, 163, 126, 198, 153, 163, 159, 151, 159)
>
> # Create a data frame
> data <- data.frame(xi, yi)
>
> # Perform linear regression
> model <- lm(yi ~ xi, data = data)
>
> # Summary of the regression model
> summary(model)

Call:
lm(formula = yi ~ xi, data = data)

Residuals:
Min 1Q Median 3Q Max
-19.095 -9.404 -1.404 6.268 34.733

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -173.513 125.765 -1.380 0.2010
xi 4.827 1.816 2.658 0.0262 *
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 16.41 on 9 degrees of freedom


Multiple R-squared: 0.4397, Adjusted R-squared: 0.3774
F-statistic: 7.063 on 1 and 9 DF, p-value: 0.02615

>
> # Make predictions for a new set of xi values (third exam scores)
> new_xi <- c(68, 72, 74)
> predicted_y <- predict(model, newdata = data.frame(xi = new_xi))
>
> # Display the predictions
> predictions <- data.frame(xi = new_xi, predicted_y)
> print(predictions)
xi predicted_y
1 68 154.7494
2 72 174.0590
3 74 183.7138
>

You might also like