You are on page 1of 10

LAB ASSIGNMENT-2

Lanka jaswanth
19BIT0061
Statistics for Engineering
MAT2001
EXPERIMENT-2
> #Correlation

> X=c(21,23,30,54,57,58,72,78,87,90)

> Y=c(60,71,72,83,110,84,100,92,113,135)

> MX=mean(X)

> MX

[1]57

> MY=mean(Y)

> MY

[1]92

> SDX=sqrt(var(X))

> SDY=sqrt(var(Y))

> SDX

[1] 25.48638

> SDY

[1] 22.82299

> cov(X,Y)
[1] 510.4444

> Cor=cov(X, Y)/(SDX*SDY)

> Cor

[1] 0.8775417

> Cor1=cor(X,Y)

> Cor1

[1] 0.8775417

> Cor2=cor.test(X,Y)

> Cor2

Pearson's product-moment correlation

data: X and Y

t = 5.1764, df = 8, p-value = 0.0008465

alternative hypothesis: true correlation is not equal to 0

95 percent confidence interval:

0.5540299 0.9707861

sample estimates:
cor

0.8775417

> #rank correlationco-efficient

> X=c(10,15,12,17,13,16,24,14,22)

> Y=c(30,42,45,46,33,34,40,35,39)

> n=length(X)

> U=rank(X)

> V=rank(Y)

> sumD2=sum ((U-V)^2)

> rankcor=1-((6*sumD2)/(n*(n^2-1)))

> rankcor

[1] 0.4

> #Linearregression

> X=c(4.7,8.2,12.4,15.8,20.7,24.9,31.9,35.0,39.1,38.8)

> Y=c(4.0,8.0,12.5,16.0,20.0,25.0,31.0,36.0,40.0,40.0)
> Reg=lm(X~Y)

> Reg

Call:

lm(formula = X ~ Y)

Coefficients:

(Intercept) Y

0.7508 0.9634

> #Multiple regression

> X1=c (30,40,20,50,60,40,20,60)

> X2=c(11,10,7,15,19,12,8,14)

> Y=c(110,80,70,120,150,90,70,120)

> multiReg=lm(Y~X1+X2)

> multiReg

Call:

lm (formula = Y ~ X1 + X2)
Coefficients:

(Intercept) X1 X2
16.8314 -0.2442 7.8488

Result:
 Correlation=0.8775417
 RankCorrelation=0.4
 Linear regression=Coefficients:

(Intercept) Y

0.7508 0.9634

 Multiple regression= Coefficients:


(Intercept) X1 X2
16.8314 -0.2442 7.8488

You might also like