You are on page 1of 3

EXPERIMENT 11

#Write a program to demonstrate line regression in R for the given dataset by


following the below steps:
 Reading and understanding the Data
 Hypothesis Testing in linear Regression
 Building a Linear Regression
 Building Analysis and Predictions

x <- c(22,49,23,13,34,5,69,31,88,65,43,32,54,34)

y <- c(34,42,68,45,13,98,55,34,4,64,45,44,21,13)

l <- lm(y~x)

summary(l)

fitted.values(lm(y~x))

plot(l, main = "Linear Regression")

residuals(lm(y~x))

confint(lm(y~x), level = 0.95)

predict(lm(y~x)

OUTPUT:

Call:

lm(formula = y ~ x)

Coefficients:

(Intercept) x

59.7158 -0.4556

> summary(l)

Call:

lm(formula = y ~ x)

Residuals:

Min 1Q Median 3Q Max

-31.227 -15.249 -4.966 15.290 40.562

Coefficients:

Estimate Std. Error t value Pr(>|t|)


(Intercept) 59.7158 13.1495 4.541 0.000676 ***

x -0.4556 0.2869 -1.588 0.138363

---

Signif. codes:

0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 23.73 on 12 degrees of freedom

Multiple R-squared: 0.1736, Adjusted R-squared: 0.1047

F-statistic: 2.52 on 1 and 12 DF, p-value: 0.1384


> fitted.values(lm(y~x))
1 2 3 4 5 6
49.69362 37.39367 49.23806 53.79360 44.22697 57.43803
7 8 9 10 11 12
28.28259 45.59363 19.62707 30.10481 40.12699 45.13808
13 14
35.11590 44.22697

You might also like