Skip to content

rnorm

Description

rnorm returns a sample of the Gaussian distribution, a symmetric “bell-shaped” distribution that is so ubiquitous that it is referred to as the “normal” distribution.

When a random variable has a number of independent and additive sources of variability, it is often described well by a Gaussian distribution. The sampling distribution of many statistics, including least-squares estimators, often tend towards a normal distribution particularly as the sample size increases.

Syntax

rnorm([rows=1], [cols=1], [mean=0], [stdev=1], [seed_str]) where

  • rows and cols describe the shape of the output
  • mean (μ\mu) and stdev (σ\sigma) are the parameters of the distribution. By default the function returns the standard normal distribution, abbreviated as z∼N(0,1)z \sim N(0,1)
  • seed_str is a memorable seed string. If omitted then a quasi-unique seed is used to generate a non-volatile output; see the documentation of runif for more detail about this. Use a memorable string of your choosing if you want to set an explicit seed for reproducibility purposes, and use GetSeed if you want a volatile output.

Leaving the seed_str blank is fine for quick & dirty work but for simulation demos you will either want to set the seed with a memorable string or make the function volatile with GetSeed. Please read the caveats about choosing seed strings in the runif documentation; they apply to this function too.

Example

100 draws from rnorm with mean 2 and SD 3, shown as a jitterplot under the normal density curve

Source Code

Basically a wrapper around NORM.INV using the output of runif as the first argument.

rnorm = LAMBDA(
    [rows], [cols],   // output size (default 1 x 1)
    [mean], [stdev],  // distribution params
    [seed_str],       // optional seed string (default uses this workbook's CLS_SystemSeed)
    LET(
        rows, IF(ISOMITTED(rows), 1, rows),
        cols, IF(ISOMITTED(cols), 1, cols),
        mean, IF(ISOMITTED(mean), 0, mean),
        stdev, IF(ISOMITTED(stdev), 1, stdev),
        seed_str, IF(
            ISOMITTED(seed_str),
            CLS_SystemSeed & ADDRESS(ROW(),COLUMN()) & "rnorm",
            seed_str
            ),
        NORM.INV(runif(rows,cols,,,,seed_str), mean, stdev)
    )
);