Skip to content

Commit fdc5196

Browse files
Update Partial Moments Equivalences.md
1 parent 387ca2f commit fdc5196

File tree

1 file changed

+27
-14
lines changed

1 file changed

+27
-14
lines changed

examples/Partial Moments Equivalences.md

+27-14
Original file line numberDiff line numberDiff line change
@@ -26,46 +26,53 @@ set.seed(123); x = rnorm(100); y = rnorm(100)
2626
### Variance
2727
A sum of the squared upside area and the squared downside area.
2828
```r
29+
# Sample Variance (base R):
2930
> 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))
3034
[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))
3338
[1] 0.8249005
39+
3440
# 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+
3744
# 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
4047
```
4148

4249
### The first 4 moments are returned with the function `NNS.moments`. For sample statistics, set `population = FALSE`.
4350
```r
44-
> NNS.moments(x)
51+
> NNS.moments(x, population = FALSE)
4552
$mean
4653
[1] 0.09040591
4754

4855
$variance
4956
[1] 0.8332328
5057

5158
$skewness
52-
[1] 0.06049948
53-
59+
[1] 0.06235774
60+
5461
$kurtosis
55-
[1] -0.161053
62+
[1] -0.1069186
5663

57-
> NNS.moments(x, population = FALSE)
64+
> NNS.moments(x, population = TRUE)
5865
$mean
5966
[1] 0.09040591
6067

6168
$variance
6269
[1] 0.8249005
63-
70+
6471
$skewness
65-
[1] 0.06235774
72+
[1] 0.06049948
6673

6774
$kurtosis
68-
[1] -0.1069186
75+
[1] -0.161053
6976
```
7077

7178
### Standard Deviation
@@ -74,6 +81,8 @@ $kurtosis
7481
[1] 0.9128159
7582
> ((UPM(2,mean(x),x)+LPM(2,mean(x),x))*(length(x)/(length(x)-1)))^.5
7683
[1] 0.9128159
84+
> sqrt(NNS.moments(x, population = FALSE)$variance)
85+
[1] 0.9128159
7786
```
7887
### Covariance
7988
```r
@@ -150,6 +159,8 @@ A normalized difference between upside area and downside area.
150159
[1] 0.06049948
151160
> ((UPM(3,mean(x),x)-LPM(3,mean(x),x))/(UPM(2,mean(x),x)+LPM(2,mean(x),x))^(3/2))
152161
[1] 0.06049948
162+
> NNS.moments(x, population = TRUE)$skewness
163+
[1] 0.06049948
153164
```
154165
### UPM/LPM - a more intuitive measure of skewness. (Upside area / Downside area)
155166
```r
@@ -164,6 +175,8 @@ A normalized sum of upside area and downside area.
164175
[1] -0.161053
165176
> ((UPM(4,mean(x),x)+LPM(4,mean(x),x))/(UPM(2,mean(x),x)+LPM(2,mean(x),x))^2)-3
166177
[1] -0.161053
178+
> NNS.moments(x, population = TRUE)$kurtosis
179+
[1] -0.161053
167180
```
168181
### CDFs
169182
```r

0 commit comments

Comments
 (0)