SDofNumDist: Standard deviation of a numerical probability density...

Description Usage Arguments Value Author(s) Examples

View source: R/statistical-functions.R

Description

Calculates the standard deviation of a numerical probability density function, i.e. a vector of values and corresponding vector of densities. It is important that the range of x values cover a sufficient fraction of the total density. For continuous distributions it should extend well into the tails. The approximation will be better the finer the resolution of x.

Usage

1

Arguments

x

vector of values

d

vector of densities, do not need to sum to 1

Value

numeric

Author(s)

Andrew Dolman <andrew.dolman@awi.de>

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
## Not run: 
if(interactive()){
 # Example 1
 x <- seq(1, 100, by = 0.01)
 d <- dnorm(x, 60, 5)
 plot(x, d, type = "l")
 SDofNumDist(x, d)

 # Example 2
 a <- 45
 b <- 55
 d2 <- dunif(x, a, b)
 plot(x, d2, type = "l")
 SDofNumDist(x, d2)

 # analytical solution for uniform distribution
 sqrt(1/12 * (b-a)^2)
 }

## End(Not run)

EarthSystemDiagnostics/ecustools documentation built on Jan. 15, 2022, 5:22 p.m.