You are on page 1of 4

Write the R code for the following.

1. Find the Karl-Pearson’s coefficient of Correlation between X and Y for


X=23,27,28,28,29,30,31,33,35,36
y=18,20,22,27,21,29,27,29,28,29
Answer: > x=c(23,27,28,28,29,30,31,33,35,36)
> y=c(18,20,22,27,21,29,27,29,28,29)
> cor.test(x,y, method="pearson")

Pearson's product-moment correlation

data: x and y
t = 4.0164, df = 8, p-value = 0.003861
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
0.3874142 0.9554034
sample estimates:
cor
0.8176052
2. For the above data find the linear regression X on Y.
Answer: > x=c(23,27,28,28,29,30,31,33,35,36)
> y=c(18,20,22,27,21,29,27,29,28,29)
> model=lm(x~y)
> model

Call:
lm(formula = x ~ y)

Coefficients:
(Intercept) y
11.25 0.75
3.

Answer:

1(i) pbinom(7,20,prob=0.5)

[1] 0.131588

(ii) 1 - pbinom(12,20,prob=0.5)

[1] 0.131588

(iii) > pbinom(12,20,prob=0.5)-pbinom(7,20,prob=0.5)


[1] 0.736824

2. (i) pbinom(79,200,prob=0.5)

[1] 0.001817474

(ii) > 1- pbinom(120,200,prob=0.5)

[1] 0.001817474

(iii) > pbinom(120,200,prob=0.5)-pbinom(79,200,prob=0.5)

[1] 0.9963651

3. (i) > pbinom(799,2000,prob=0.5)

[1] 1.162645e-19

(ii) 1 - pbinom(1200,2000,prob=0.5)

[1] 1.162645e-19

(iii) > pbinom(1200,2000,prob=0.5)-pbinom(799,2000,prob=0.5)

[1] 1

4. (i) > 1- pbinom(5,10,prob=0.5)

[1] 0.3769531

(ii) > dbinom(5,10,prob=0.5)

[1] 0.2460938

(iii) > pbinom(6,10,prob=0.5)-pbinom(3,10,prob=0.5)

[1] 0.65625

5. (i) > ppois(15, 12.33, lower.tail = TRUE)

[1] 0.8195608

(ii) > dpois(16, 12.33)

[1] 0.06024745

(iii) > ppois(16, 12.33, lower.tail = FALSE)


[1] 0.1201917

(iv) > ppois(15, 12.33, lower.tail = FALSE)

[1] 0.1804392

(v) > ppois(10, 12.33, lower.tail = TRUE)-ppois(8, 12.33, lower.tail = FALSE)

[1] -0.5518197

6. Binomial = > pbinom(X,100,prob=0.5)

[1] 1.608001e-05

Poisson= > ppois(X, 100, lower.tail = TRUE)

[1] 5.89326e-17

7. Binomial= > pbinom(X,1000,prob=0.5)

[1] 7.220755e-246

Poisson= > ppois(X, 1000, lower.tail = TRUE)

[1] 0

You might also like