-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
445 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
^CRAN-RELEASE$ | ||
^.*\.Rproj$ | ||
^\.Rproj\.user$ | ||
^README\.Rmd$ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,3 +27,4 @@ vignettes/*.pdf | |
.Rproj.user | ||
*.Rproj | ||
README.html | ||
CRAN-RELEASE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
--- | ||
title: "testing variance computation with expected value and sigma" | ||
output: html_notebook | ||
--- | ||
|
||
Formula for Variance given sigma at log scale and expected value | ||
|
||
We start with formulas for variance and mean. | ||
$$ | ||
V = (e^{\sigma^2} - 1) e^{2\mu + \sigma^2} \\ | ||
m = e^{\mu + \sigma^2/2} | ||
$$ | ||
mean formula resolved for $\mu$ and substituted into V. | ||
$$ | ||
\mu = log_m - \sigma^2/2 \\ | ||
V = (e^{\sigma^2} - 1) e^{2(log_m - \sigma^2/2) + \sigma^2} \\ | ||
V = (e^{\sigma^2} - 1) e^{2log_m - \sigma^2 + \sigma^2} \\ | ||
V = (e^{\sigma^2} - 1) e^{2log_m} \\ | ||
V = (e^{\sigma^2} - 1) (e^{log_m})^2 \\ | ||
V = (e^{\sigma^2} - 1) m^2 \\ | ||
$$ | ||
|
||
|
||
```{r} | ||
n = 1e4 | ||
sigma = log(1.2) | ||
#sigma = log(1.41) | ||
mu = log(10) | ||
logR = rnorm(n, mu, sigma) | ||
R = exp(logR) | ||
meanR = mean(R) | ||
sdR = sd(R) | ||
V2 = (exp(sigma^2) - 1)*exp(2*mu + sigma^2) | ||
# | ||
m = exp(mu + sigma^2/2) | ||
V = (exp(sigma^2) - 1)*m^2 | ||
c(meanR, m) | ||
c(sdR, sqrt(V), sqrt(V2)) | ||
``` | ||
```{r} | ||
xPred <- seq(-2,22,length.out = 101) | ||
plot(density(R), xlim = c(-2,22), lty = "dotted") | ||
abline(v = meanR) | ||
lines(dnorm(xPred, m, sqrt(V))~xPred, col = "blue", lty = "dashed") | ||
lines(dlnorm(xPred, mu, sigma)~xPred, col = "green") | ||
``` | ||
```{r} | ||
df <- data.frame(nu = c(0.05,0.1,0.2,0.5,1,2,5,10,20)) | ||
df$sigmaStar = sqrt(df$nu^2 + 1) | ||
df | ||
``` | ||
```{r} | ||
plot(sigmaStar ~ nu, df[1:3,]) | ||
``` | ||
|
||
```{r} | ||
sigmaStar <- 1.2 | ||
(nu <- sqrt(sigmaStar^2 - 1)) | ||
``` | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters