@@ -26,46 +26,53 @@ set.seed(123); x = rnorm(100); y = rnorm(100)
26
26
### Variance
27
27
A sum of the squared upside area and the squared downside area.
28
28
``` r
29
+ # Sample Variance (base R):
29
30
> var(x )
31
+ [1 ] 0.8332328
32
+ > # Sample Variance:
33
+ > (UPM(2 , mean(x ), x ) + LPM(2 , mean(x ), x )) * (length(x ) / (length(x ) - 1 ))
30
34
[1 ] 0.8332328
31
- # Sample Variance:
32
- > UPM(2 ,mean(x ),x )+ LPM(2 ,mean(x ),x )
35
+
36
+ # Population Adjustment of Sample Variance (base R):
37
+ > var(x ) * ((length(x ) - 1 ) / length(x ))
33
38
[1 ] 0.8249005
39
+
34
40
# Population Variance:
35
- > (UPM(2 ,mean(x ),x )+ LPM(2 ,mean(x ),x ))* (length(x )/ (length(x )- 1 ))
36
- [1 ] 0.8332328
41
+ > UPM(2 , mean(x ), x ) + LPM(2 , mean(x ), x )
42
+ [1 ] 0.8249005
43
+
37
44
# Variance is also the co-variance of itself:
38
- > (Co.LPM(1 ,x , x , mean(x ),mean(x ))+ Co.UPM(1 ,x , x , mean(x ),mean(x ))- D.LPM(1 ,1 , x , x , mean(x ),mean(x ))- D.UPM(1 ,1 , x , x , mean(x ),mean(x ))) * (length( x ) / (length( x ) - 1 ))
39
- [1 ] 0.8332328
45
+ > (Co.LPM(1 , x , x , mean(x ), mean(x )) + Co.UPM(1 , x , x , mean(x ), mean(x )) - D.LPM(1 , 1 , x , x , mean(x ), mean(x )) - D.UPM(1 , 1 , x , x , mean(x ), mean(x )))
46
+ [1 ] 0.8249005
40
47
```
41
48
42
49
### The first 4 moments are returned with the function ` NNS.moments ` . For sample statistics, set ` population = FALSE ` .
43
50
``` r
44
- > NNS.moments(x )
51
+ > NNS.moments(x , population = FALSE )
45
52
$ mean
46
53
[1 ] 0.09040591
47
54
48
55
$ variance
49
56
[1 ] 0.8332328
50
57
51
58
$ skewness
52
- [1 ] 0.06049948
53
-
59
+ [1 ] 0.06235774
60
+
54
61
$ kurtosis
55
- [1 ] - 0.161053
62
+ [1 ] - 0.1069186
56
63
57
- > NNS.moments(x , population = FALSE )
64
+ > NNS.moments(x , population = TRUE )
58
65
$ mean
59
66
[1 ] 0.09040591
60
67
61
68
$ variance
62
69
[1 ] 0.8249005
63
-
70
+
64
71
$ skewness
65
- [1 ] 0.06235774
72
+ [1 ] 0.06049948
66
73
67
74
$ kurtosis
68
- [1 ] - 0.1069186
75
+ [1 ] - 0.161053
69
76
```
70
77
71
78
### Standard Deviation
@@ -74,6 +81,8 @@ $kurtosis
74
81
[1 ] 0.9128159
75
82
> ((UPM(2 ,mean(x ),x )+ LPM(2 ,mean(x ),x ))* (length(x )/ (length(x )- 1 )))^ .5
76
83
[1 ] 0.9128159
84
+ > sqrt(NNS.moments(x , population = FALSE )$ variance )
85
+ [1 ] 0.9128159
77
86
```
78
87
### Covariance
79
88
``` r
@@ -150,6 +159,8 @@ A normalized difference between upside area and downside area.
150
159
[1 ] 0.06049948
151
160
> ((UPM(3 ,mean(x ),x )- LPM(3 ,mean(x ),x ))/ (UPM(2 ,mean(x ),x )+ LPM(2 ,mean(x ),x ))^ (3 / 2 ))
152
161
[1 ] 0.06049948
162
+ > NNS.moments(x , population = TRUE )$ skewness
163
+ [1 ] 0.06049948
153
164
```
154
165
### UPM/LPM - a more intuitive measure of skewness. (Upside area / Downside area)
155
166
``` r
@@ -164,6 +175,8 @@ A normalized sum of upside area and downside area.
164
175
[1 ] - 0.161053
165
176
> ((UPM(4 ,mean(x ),x )+ LPM(4 ,mean(x ),x ))/ (UPM(2 ,mean(x ),x )+ LPM(2 ,mean(x ),x ))^ 2 )- 3
166
177
[1 ] - 0.161053
178
+ > NNS.moments(x , population = TRUE )$ kurtosis
179
+ [1 ] - 0.161053
167
180
```
168
181
### CDFs
169
182
``` r
0 commit comments