Lines of Regression, Angle between two lines of regression and estimated values of variables. Experiment :1 Finding (a) Regression line of y on x and (b) Regression line of x on y. Experiment :2 Predicting y value for a given x. Experiment :3 Angle between two lines of regression

 #Lines of Regression a)

x=c(14,19,24,21,26,22,15,20,19)
y=c(31,36,48,37,50,45,33,41,39)
relation=lm(y~x)
print(relation)
#Lines of Regression 2
x=c(14,19,24,21,26,22,15,20,19)
y=c(31,36,48,37,50,45,33,41,39)
relation1=lm(x~y)
print(relation1)

#2)Prediction y values for x
x =c(151,174,138,186,128,136,179,163,152,131)
y =c(63,81,56,91,47,57,76,72,62,48)
relation= lm(y~x)
a = data.frame(x=170)
result = predict(relation,a)
print(result)

#3) Angle Between Two Lines of regression
x=c(14,19,24,21,26,22,15,20,19)
y=c(31,36,48,37,50,45,33,41,39)
r1=lm(y~x)
r2=lm(x~y)
m1=r1$coeff[2]
m2=1/r2$coeff[2]
angle=atan((m2-m1)/(1+m1*m2))*180/pi
abs(angle)

#Student Task 1
x=c(1,3,4,6,8,9,11,14)
y=c(1,2,4,4,5,7,8,9)
print(lm(y~x))
print(lm(x~y))

#Predict()
x =c(12,14,32,65,21)
y =c(2,4,3,5,9)
relation= lm(y~x)
b = data.frame(x=80)
result2 = predict(relation,b)
print(result2)

#Angle Between Two Lines of regression
x=c(3,6,8,11,34,32)
y=c(12,9,4,8,7,16)
r1=lm(y~x)
r2=lm(x~y)
m3=r1$coeff[2]
m3
m4
m4=1/r2$coeff[2]
angle2=atan((m4-m3)/(1+m3*m4))*180/pi
abs(angle2)
r1
r2


Comments

Popular posts from this blog

Probability distributions using R Experiment :1 Binomial Distribution Experiment :2 Poisson Distribution Experiment :3 Normal Distribution