R Lab Ex 6 To 8
R Lab Ex 6 To 8
REGRESSION MODEL
(A) R program to illustrate Linear Regression
# Height vector
x <- c(153, 169, 140, 186, 128,136, 178, 163, 152, 133)
# Weight vector
y <- c(64, 81, 58, 91, 47, 57,75, 72, 62, 49)
# Create a linear regression model
model <- lm(y~x)
# Print regression model
print(model)
OUTPUT:
Call:
lm(formula = y ~ x)
Coefficients:
(Intercept) x
-39.7137 0.6847
OUTPUT:
abline(lm(y~x))
# Save the file.
dev.off()
OUTPUT:
Call:
lm(formula = Ozone ~ Wind + Temp, data = input)
Coefficients:
(Intercept) Wind Temp
-58.239 -0.739 1.329
# Plot
plot(model)
OUTPUT:
# Save the file.
dev.off()
# Print model
print(model)
OUTPUT:
Call: glm(formula = vs ~ wt, family = binomial, data = mtcars)
Coefficients:
(Intercept) wt
5.715 -1.911