Created
December 29, 2025 10:18
-
-
Save abikoushi/1d084f34ae30a55543f4554cdc75e308 to your computer and use it in GitHub Desktop.
Canonical form parametrized normal distribution
This file contains hidden or 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
| rcfnorm <- function(n, shape=0, inv_scale=1){ | |
| rnorm(n, shape/inv_scale, 1/sqrt(inv_scale)) | |
| } | |
| dcfnorm <- function(n, shape=0, inv_scale=1, ...){ | |
| dnorm(n, shape/inv_scale, 1/sqrt(inv_scale), ...) | |
| } | |
| pcfnorm <- function(n, shape=0, inv_scale=1, ...){ | |
| pnorm(n, shape/inv_scale, 1/sqrt(inv_scale), ...) | |
| } | |
| a1 = 1; b1 = 0.5 | |
| a2 = 2; b2 = 2.5 | |
| x1 = rcfnorm(10000, a1, b1) | |
| x2 = rcfnorm(10000, a2, b2) | |
| x = x1+x2 | |
| hist(x, breaks = "scott", freq=FALSE) | |
| B = 1/(1/b1+1/b2) | |
| A = B*(a1/b1+a2/b2) | |
| curve(dcfnorm(x, A, B), add=TRUE, col="orangered") | |
| plot(ecdf(x1+x2)) | |
| curve(pcfnorm(x, A, B), add=TRUE, col="orangered", lty=2) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment