import numpy as np
import scipy as sp
from scipy.stats import norm

### Correlation and Regression Lines – A Quick Recap #1

Here are the test scores of 10 students in physics and history:

Physics Scores 15 12 8 8 7 7 7 6 5 3

History Scores 10 25 17 11 13 17 20 13 9 15

Compute Karl Pearsonâ€™s **coefficient of correlation** between these scores. Compute the answer correct to three decimal places.

**Output Format**

In the text box, enter the floating point/decimal value required. Do not leave any leading or trailing spaces. Your answer may look like: `0.255`

This is NOT the actual answer – just the format in which you should provide your answer.

physicsScores=[15, 12, 8, 8, 7, 7, 7, 6, 5, 3]
historyScores=[10, 25, 17, 11, 13, 17, 20, 13, 9, 15]

print(np.corrcoef(historyScores,physicsScores)[0][1])

```
0.144998154581
```

### Correlation and Regression Lines – A Quick Recap #2

Here are the test scores of 10 students in physics and history:

Physics Scores 15 12 8 8 7 7 7 6 5 3

History Scores 10 25 17 11 13 17 20 13 9 15

Compute the **slope of the line of regression** obtained while treating Physics as the independent variable. Compute the answer correct to three decimal places.

**Output Format**

In the text box, enter the floating point/decimal value required. Do not leave any leading or trailing spaces. Your answer may look like: `0.255`

This is NOT the actual answer – just the format in which you should provide your answer.

sp.stats.linregress(physicsScores,historyScores).slope

```
0.20833333333333331
```

### Correlation and Regression Lines – A quick recap #3

Here are the test scores of 10 students in physics and history:

Physics Scores 15 12 8 8 7 7 7 6 5 3

History Scores 10 25 17 11 13 17 20 13 9 15

When a student scores 10 in Physics, what is his probable score in History? Compute the answer correct to one decimal place.

**Output Format**

In the text box, enter the floating point/decimal value required. Do not leave any leading or trailing spaces. Your answer may look like: `0.255`

This is NOT the actual answer – just the format in which you should provide your answer.

def predict(pi,x,y):
slope, intercept, rvalue, pvalue, stderr=sp.stats.linregress(x,y);
return slope*pi+ intercept
predict(10,physicsScores,historyScores)

```
15.458333333333332
```

### Correlation and Regression Lines – A Quick Recap #4

The two regression lines of a bivariate distribution are:

`4x â€“ 5y + 33 = 0`

(line of y on x)

`20x â€“ 9y â€“ 107 = 0`

(line of x on y).

Estimate the value of `x`

when `y = 7`

. Compute the correct answer to one decimal place.

**Output Format**

In the text box, enter the floating point/decimal value required. Do not lead any leading or trailing spaces. Your answer may look like: `7.2`

This is NOT the actual answer – just the format in which you should provide your answer.

x=[i for i in range(0,20)]
'''
4x - 5y + 33 = 0
x = ( 5y - 33 ) / 4
y = ( 4x + 33 ) / 5
20x - 9y - 107 = 0
x = (9y + 107)/20
y = (20x - 107)/9
'''
t=7
print( ( 9 * t + 107 ) / 20 )

```
8.5
```

#### Correlation and Regression Lines – A Quick Recap #5

The two regression lines of a bivariate distribution are:

`4x â€“ 5y + 33 = 0`

(line of y on x)

`20x â€“ 9y â€“ 107 = 0`

(line of x on y).

find the variance of y when Ïƒx= 3.

Compute the correct answer to one decimal place.

**Output Format**

In the text box, enter the floating point/decimal value required. Do not lead any leading or trailing spaces. Your answer may look like: `7.2`

This is NOT the actual answer – just the format in which you should provide your answer.

#### Q.3. If the two regression lines of a bivariate distribution are 4x â€“ 5y + 33 = 0 and 20x â€“ 9y â€“ 107 = 0,

- calculate the arithmetic means of x and y respectively.
- estimate the value of x when y = 7. – find the variance of y when Ïƒx = 3.

##### Solution : â€“

We have,

4x â€“ 5y + 33 = 0 => y = 4x/5 + 33/5 â€”â€”â€”â€”â€” (i)

And

20x â€“ 9y â€“ 107 = 0 => x = 9y/20 + 107/20 â€”â€”â€”â€”- (ii)

(i) Solving (i) and (ii) we get, mean of x = 13 and mean of y = 17.[Ans.]

(ii) Second line is line of x on y

x = (9/20) Ã— 7 + (107/20) = 170/20 = 8.5 [Ans.]

(iii) byx = r(Ïƒy/Ïƒx) => 4/5 = 0.6 Ã— Ïƒy/3 [r = âˆš(byx.bxy) = âˆš{(4/5)(9/20)]= 0.6 => Ïƒy = (4/5)(3/0.6) = 4 [Ans.]

variance= Ïƒ**2=> 16