summaryrefslogtreecommitdiff
path: root/331/CH10/EX10.1/Example_10_1.sce
blob: 030f8e5bd58da25e05a0d5198d6bde38e419909c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//Caption:Correlation Analysis
//Correlation Coefficient for Ungrouped Data (karl Pearson's Coefficient of Correlation)
//The combination of hypotheses too test the significance of 'r' is as shown below:
//Ho: r =0 (The two variables are not associated)
//H1: r # 0 (The two variables are associated)
//Example10.1
//Page368
clear;
clc;
X = [10,12,14,16,18,20,22,24,26,28];//Annual Advertising expenditure
Y = [20,30,37,50,56,78,89,100,120,110];//Annual sales
n = length(X);
Xmean = mean(X);
Ymean = mean(Y);
disp(Xmean,'Mean of X=')
disp(Ymean,'Mean of Y=')
//correlation coefficient using basic formula
r=0;
num=0;
den1=0;
den2=0;
for i = 1:n
    num=num+((X(i)-Xmean)*(Y(i)-Ymean))
    den1 = den1+(X(i)-Xmean)^2;
    den2 = den2+(Y(i)-Ymean)^2;
end
r = num/(sqrt(den1)*sqrt(den2));
disp(r,'The correlaion coefficient between annual advertising expenditure and annual sales revenue r =')
//correlation coefficient using Pearson's product moment formula
sumxi = sum(X);
sumyi = sum(Y);
xiyi = X.*Y;
sumxiyi = sum(xiyi);
sumxi2 = sum(X.^2);
sumyi2 = sum(Y.^2);
r = (n*sumxiyi-sumxi*sumyi)/(sqrt(n*sumxi2-sumxi^2)*sqrt(n*sumyi2-sumyi^2));
disp(r,'The correlation coefficient using Pearsons product moment formula r=')
t = r/sqrt((1-r^2)/(n-2));
disp(t,'The calculated t statistic to test the significance of r t=')
alpha = 0.05;
alpha = alpha/2;
t_stand = 2.306;
disp(t_stand,'The table t value at half of the significance level and 8 degrees of freedom=')
if (t<t_stand) then
    disp('Since the calculated t statistic is less than table t value, accept Null hypothesis')
else
    disp('Since the calculated t statistic is greater than table t value, reject Null hypothesis')
end
//Result
//Mean of X=   
// 
//    19.  
// 
// Mean of Y=   
// 
//    69.  
// 
// The correlaion coefficient between annual advertising expenditure and annual sales revenue r =   
// 
//    0.9851764  
// 
// The correlation coefficient using Pearsons product moment formula r=   
// 
//    0.9851764  
// 
// The calculated t statistic to test the significance of r t=   
// 
//    16.243604  
// 
// The table t value at half of the significance level and 8 degrees of freedom=   
// 
//    2.306  
// 
// Since the calculated t statistic is greater than table t value, reject Null hypothesis