T.Y.BSc(I.
T) SEM-VI Business Intelligence
Practical No.9
Perform the Linear regression on the given data warehouse data.
Regression
In statistical modeling, regression analysis is a set of statistical processes for estimating the
relationships between a dependent variable and one or more independent variables
Linear Regression
In Linear Regression these two variables are related through an equation, where exponent
(power) of both these variables is 1.
y = ax + b is an equation for linear regression.
Where, y is the response variable, x is the predictor variable and a and b are constants which
are called the coefficients.
lm() Function
In R, the lm(), or “linear model,” function can be used to create a simple regression model. The
lm() function accepts a number of arguments (“Fitting Linear Models,” n.d.).
x <- c(151, 174, 138, 186, 128, 136, 179, 163, 152, 131)
.
y <- c(63, 81, 56, 91, 47, 57, 76, 72, 62, 48)
# Apply the lm() function.
relation <- lm(y~x)
# Find weight of a person with height 170.
a <- data.frame(x = 170)
result <- predict(relation,a)
print(result)
# Give the chart file a name.
png(file = "linearregression.png")
# Plot the chart.
plot(y,x,col = "blue",main = "Height & Weight Regression",
abline(lm(x~y)),cex = 1.3,pch = 16,xlab = "Weight in Kg",ylab = "Height in cm")
# Save the file.
dev.off()
Compiled By. Prof. Ansari Mohd. Shahid & Prof.Farzin Qureshi
T.Y.BSc(I.T) SEM-VI Business Intelligence
Compiled By. Prof. Ansari Mohd. Shahid & Prof.Farzin Qureshi