Showing posts with label Correlation. Show all posts
Showing posts with label Correlation. Show all posts

Thursday, May 21, 2020

R for MBA's- correlation using R

Correlation using R


Problem 1: 


> x<-c(143,175,156,187,195)
> y<-c(132,191,111,156,175)
> cor(x,y)

Ans: [1] 0.7017061

Wednesday, May 20, 2020

Python for MBA's- Correlation using Python


Method 1: Using Numpy Library

import numpy as np
advt=[5,10,15,20,25]
sales=[40,60,80,100,120]
a=np.corrcoef(advt,sales)
print(a)
Ans:
[[1. 1.]
 [1. 1.]]
 

Method 2: Using Scipy library

Problem2: Find the correlation between share volume of  Ajit 

industries and market volume of a sensex. The data is given below:

share volume : 25,35,28,22,34,32

Market volume: 35,55,42,36,45,41

Solution:

Coding:
 
import numpy as np
from scipy.stats import pearsonr
sharevolume=[25,35,28,22,34,32]
marketvolume=[35,55,42,36,45,41]
pearsonr(sharevolume,marketvolume)

Output

(0.8440172720849535, 0.034598339542112846)