This page consolidates notes from CEE308 Environmental Engineering Lab at Princeton University, Spring 2022, taught by Professor Peter Jaffe.

Mean, variance, and standard deviation from n direct measurements

The mean Λ‰x is calculated as:

Λ‰x=βˆ‘ixin

Where Λ‰x is the mean, xi is the i-th measurement, and n is the number of measurements.

If the true standard error Οƒ or variance Οƒ2 for the population is known, and if the mean Λ‰x was estimated from n samples, then variance of the mean Οƒ2Λ‰x can be calculated as

Οƒ2Λ‰x=Οƒ2n

If the variance S2 of the population is not known and must be estimated (as in most cases), then use the following equation:

S2=1nβˆ’1βˆ‘i(xiβˆ’Λ‰x)2

Where in all these equations:

  • Οƒ refers to the true error
  • S refers to the estimated error

Least-squares Linear Regression

Suppose you want to fit the function

y=a+bx

to a set of 2D data of n samples. Then parameters a and b can be estimated using the following equations:

a=βˆ‘ix2iβˆ‘iyiβˆ’βˆ‘ixiβˆ‘ixiyinβˆ‘ix2iβˆ’(βˆ‘ixi)2 b=nβˆ‘ixiyiβˆ’βˆ‘ixiβˆ‘yinβˆ‘ix2iβˆ’(βˆ‘ixi)2

Where, for clarity, a is the intercept and b is the slope of the regression.

Parameter error estimation

The set of residuals E can be defined as the set of differences between the original y-values and the y-values estimated by the regression using the original x-values as arguments:

E={Ο΅i:Ο΅i=yiβˆ’(a+bxi),βˆ€(xi,yi)}

Then the variance of the regression model can be calculated as follows:

S2y/x=1nβˆ’2βˆ‘iΟ΅2i,βˆ€Ο΅i∈E

And the variance of the slope b:

S2b=S2y/xβˆ‘i(xiβˆ’Λ‰x)2

And the variance of the intercept a:

S2a=S2x/y(1n+Λ‰x2βˆ‘i(xiβˆ’Λ‰x)2)

Note that the error S (usually denoted Οƒ, even when estimated) of either parameter is simply the square root of the respective variance.

Therefore when writing a technical paper where you produce β€œerror bars” or Β± standard deviation, calculate Οƒ=√S2 for each determined parameter.

Error propagation

Given the analytical model

y=f(x1,x2,...,x3)

Then the variance of the model is

Οƒ2y=βˆ‘iΟƒ2Λ‰x,ixi(βˆ‚yβˆ‚xi)2