Docsity

Linear Regression Models: Theoretical vs. Empirical, Study notes of Advanced Physics

Toggle sidebar
bg1
Modeling
Just knowing that there is an effect
or having some idea as to its source
may not be very useful.
We want to be able to:
•make predictions
•estimate the effects of levels not
studied
We must develop a model.
Types of models
Theoretical (parametric) model
Data follows from a theory.
Uses known theoretical laws or principles.
Example - Calibration curve of
absorbance vs. concentration.
While the model may not be linear, we
typically attempt to transform it to make
it linear.
Types of models
Empirical (nonparametric) model.
No theoretical basis for the model.
An equation is simply fit to the data.
You must assume that the trend
continues outside the experimental
ranges.
Example - polynomial fit of a GC trace.
Example
Linear fit of a theoretical relationship.
concentration
absorbance, 550nm
If X is known and we control it, then
σ2X = 0 and a b1 (slope) is found that
minimizes:
We simply want to minimize the
difference the measured and
predicted values.
vy
2
Yi-Y
^
` j
!
Y
^=predicted
2
Linear model
We’re just trying to minimize the standard error (SE) for
our model.
The optimum value for b1 is the one that minimizes the
standard error.
We also must assume that the values are homoscedastic:
(unweighted least squares)
vy1
2=vy2
2=....=vyn
2
SE =vy
2
Yi-Y
^
` j
!=vy
2
1
!Yi-biXi
^ h
2
2
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download Linear Regression Models: Theoretical vs. Empirical and more Study notes Advanced Physics in PDF only on Docsity!

Modeling

Just knowing that there is an effect

or having some idea as to its source

may not be very useful.

We want to be able to:

  • make predictions
  • estimate the effects of levels not studied

We must develop a model.

Types of models

Theoretical (parametric) model

Data follows from a theory.

Uses known theoretical laws or principles.

Example - Calibration curve of absorbance vs. concentration.

While the model may not be linear, we typically attempt to transform it to make it linear.

Types of models

Empirical (nonparametric) model. No theoretical basis for the model. An equation is simply fit to the data.

You must assume that the trend continues outside the experimental ranges.

Example - polynomial fit of a GC trace.

Example

Linear fit of a theoretical relationship.

concentration

absorbance, 550nm

Linear models, Y = b 1 X

If X is known and we control it, then

σ^2 X = 0 and a b 1 (slope) is found that

minimizes:

We simply want to minimize the

difference the measured and

predicted values.

v (^) y^2

Y i - Y

` ^j

! Y

^ = predicted

2

Linear model

We’re just trying to minimize the standard error (SE) for our model.

The optimum value for b1 is the one that minimizes the standard error. We also must assume that the values are homoscedastic: (unweighted least squares)

v (^) y^21 =v (^) y^22 =....=v (^) yn^2

SE = (^) v y^2

` Y (^) (^) i - Y^ ^j ! = (^) v y^2

! 1 ^ Y^ i - b i X i h^2

2

Homoscedatic data

homoscedastic not homoscedastic

Linear model

To find the value of b 1 that minimizes

the standard error, we set:

Solving for b 1 gives

2 b 1

2 SE

& b 1! x i^2 = ! x i y i

b 1 =

! x^ i^2

!^ x^ i^ y^ i

Linear model

Weighted least squares

Used when the data is not homoscedastic.

Each measurement is weighted by the

reciprocal of its variance.

b 1 =

v (^) y^21

x (^) i^2

v (^) y^21

x (^) i y (^) i

_ v 2 y 1! v 2 y 2! ....! v yn^2 !i

Example ppm abs xy x^2 1 0.020 0.020 1 2 0.038 0.076 4 3 0.064 0.192 9 4 0.077 0.308 16 5 0.105 0.525 25 sums 1.121 55

b 1 =

! x^ i^2

!^ x^ i^ y^ i

=0.0204 so Y =0.0204 X

Y-intercept

What if your data does not go

through the origin?

Y-intercept = Y - b 1 X

You simply need to calculate the

mean for both X and Y and use the

above equation.

How good is the fit?

An ANOVA can can be conducted to determine

the ‘goodness of fit’ for the model.

a y - y^ ^k

2

a y i - y^ ^k

2

_ y i - y i

2

Source of Variance Sum of Squares DF

Model p

Residual n-p-

Total n-

p = number of parameters.

n = number of data points.

Correlation coefficient

Correlation, |r| (^) 100 r 2 0.10 1 0.20 4 0.50 25 0.80 64 0.90 81 0.95 90 0.99 99 1.00 100

Relationship between correlation coefficient (r) and proportion of variance (r^2 ).

|r| values

below 0.

indicate a poor

relationship.

Correlation coefficient

Y

X

Y

X Y

X

Y

X

r = 0.

r = 1.

r = -1.

r = 0.

The same thing with Excel

It should come as no surprise that we can do the same calculations using Excel.

Two approaches Data analysis add-on Detailed analysis Trendlines Quick and dirty regression lines when producing a graph.

Excel Data Analysis add-on

Excel Data Analysis add-on Excel trendline

Excel trendline Excel trendline

Excel trendline Excel trendline

Data transformations

In some cases, it is best to do a

simple transformation of your data

prior to attempting a linear

regression fit.

The goal of the transformation is to

make the resulting relationship

linear.

An ANOVA analysis can be conducted

on the transformed data.

Data transformations

Transform Equation of the line Y X Y = b X + a Y 1/X Y = a + b / X 1/Y X Y = 1 / ( a + b X ) X/Y X Y = X / ( a + b X ) log Y X Y = a b X log Y log X Y = a Xb Y Xn^ Y = a + b X n

b = slope, a = intercept.

Multiple linear regression

MLR assumes a linear relationship between Xi and y, with superimposed noise (e). It

also assumes that there are no interactions between X 1 , X 2 , … Xn.

Y = b 0 + b 1 X 1 + b 2 X 2 +.... bnXn + e

We then ‘fit’ a regression equation. The bn values are considered to be estimates of the true population parameters, βn.

Multiple linear regression

For a two variable model:

As in the one variable model, we end up

with:

We can then solve these two ‘normal

equations.’ It becomes more difficult

as additional variables are added in.

Y = b 1 X 1 + b 2 X 2

b 1! X (^) 12 + b (^) 2! X (^) 1 X (^) 2 = (^)! YX (^) 1 b (^) 2! X (^) 22 + b 1! X (^) 1 X (^) 2 = (^)! YX (^) 2

Multiple linear regression

Results must be interpreted more carefully that with simple regression. All of the b values are now tied together and must be interpreted as a group.

R^2 values will increase as you add additional X values to the model - even random numbers.

Use adjusted R^2 values to see if new predictors improved model.

Multiple linear regression

R^2 simply looks a how well all of the X

account for Y. The adjusted R^2 is weighted

by the number of X used.

R^2 =

SS Total

SS Total - SS residual

adjusted R^2 =

MS Total

MS Total - MS residual

Multiple linear regression

One advantage of an MLR approach is that you can obtain multiple measurements (X) for a single response. This can help eliminate noise.

We’ll look at one example using MLR - Determination of Octane Number by NIR.

We’ll revisit this example in a later unit when we compare it to other multivariate calibration methods.

Octane number

Rating Octane of Gasoline using near-IR. ASTM method is complex and expensive. A simple spectral method would be more desirable.

Experimental A series of unleaded gasoline samples were assayed by the ASTM method. NIR spectra (900-1600 nm) were also obtained. A matrix was constructed from the spectra (20 nm intervals) were the X matrix and the ASTM octane number was the Y matrix.

A 915 nm, CH 2 stretch B 1021 nm, CH 2 /CH 3 combination band C 1151 nm, aromatic and CH 3 stretch D 1194 nm, CH 3 stretch E 1394 nm, CH 2 combination bands F 1412 nm aromatic & CH 2 combination bands G 1435 nm aromatic & CH2 combination bands

Octane Number, NIR spectra

(^900 1000 1100 1200) Wavelength 1300 1400 1500 1600

Absorbance A

C B

D

C

E

F

G

Octane Number, XLStat MLR

Single variable - 900 - just for comparison.

Octane Number, MLR Octane Number, MLR

80

82

84

86

88

90

92

94

96

98

0.21 0.215 0.22 0.225 0.23 0. 900

Octane #

Active Validation Model Conf. interval(Mean 95%) Conf. interval (Obs. 95%)

Using the ‘best’ 4 lines Pred(Octane #) / Octane #

83

85

87

89

91

93

83 85 87 89 91 93 Pred(Octane #)

Octane # No significant change in the quality of the fit. Means you only need 4 lines to determine octane number.

Pred(Octane #) / Standardized residuals

-2.5-

-1.5-

-0.5^0

0.5^1

1.5^2 83 85 87 89 91 93

Pred(Octane #)

Standardized residuals

ANCOVA

XLStat does a good job of switching to

the proper type of model based on the

type of data.

Number of X variables Qual^ Quant^ Mixed

(^1) ANOVASimple LR -

2 or more ANOCA MLR ANCOVA

ANCOVA

You can use the method to tell:

If the qualitative variables are

significant.

If one gets the same basic model

(slope) for the quantitative variables.

If you can build a model that can

account for both types of factors

(when significant.)

ANCOVA examples

Both treatment and covariate variables are significant with the same model.

Covariate variable is significant, treatment is not.

Neither are significant. Both treatment and covariate variables are significant.

Treatment issignificant but covariate isnʼt.

Both treatment and covariate variables are significant but the models are different.

Modified Octane example

The near IR spectra can vary based not only on octane number.

The presence of oxygenates can cause changes.

Seasonal blends can also cause changes.

ANCOVA can be used to deal with this type of situation.

For simplicity, we’ll look at a

single near IR region. It has

one of the highest correlations

with octane number of those

evaluated earlier.

Start with a simple linear

regression analysis, ignoring

the fact there are both summer

and winter blends included.

80

82

84

86

88

90

92

94

96

0.34 0.36 0.38 0.4 0. a

Octane #

Active Model Conf. interval (Mean 95%) Conf. interval (Obs. 95%)

Standardized residuals / a

-1.

-0.

0

1

2

0.34 0.36 0.38 0.4 0.

a

Standardized residuals Octane # / Standardized residuals

-1.

-0.

0

1

2

83 85 87 89 91 93

Octane #

Standardized residuals

It seems pretty clear that a simple linear regression has a problem. It is also obvious that there are two types of samples.

Evaluating a simple scatterplot may help.

y = 0.0023x + 0.159R 2 = 0.

y = 0.0021x + 0.2249R 2 = 0.

83.0 84.0 85.0 86.0 87.0 88.0 89.0 90.0 91.0 92.0 93.

SummerWinter Linear (Summer)Linear (Winter)

Let’s try an ANCOVA - using a1360 as the covariate and the ‘blend’ type as an additional factor.

Pred(Octane #) / Octane #

83

85

87

89

91

93

(^83 85) Pred(Octane #) 87 89 91 93

Octane # Octane # / Standardized residuals

-1.

-0.

0

1

2

3

83 85 87 89 91 93

Octane #

Standardized residuals

Non-linear regression

With many problems, it is not always possible to set up a simple linear regression solution, even with data transformation.

Non-linear regression methods permit the user to fit a set of parameters to a model which can involve many variables.

This type of problem is typically solved using a computer program.

Response surface

Yi

f(x)

error

This can be more difficult as the number of

adjustable parameters increases. There can

be several false minima that must be avoided.

Non-linear regression options

Most programs include a range of

options you can select or modify.

This not only permits you to

speed up processing time

avoid false convergence.

control the tolerance of your fit

Non-linear regression options

Typical options Initial estimate of parameters An initial guess of your values can not only save processing time but avoid false convergence as well.

Scaling of parameters The magnitude of your parameters can vary greatly. Scaling will give them comparable ‘weight’ during the fit.

Non-linear regression options

First Derivative Function Some programs require that you provide the first derivative (Jacobian) for your function. It is used to determine the best direction to try it’s next estimate.

Tolerance Various types including how big a jump it can make to the next estimate, how good the numbers are, ...

Non-linear regression options

Maximum iterations How many ‘guesses’ it should attempt before quitting.

Limits Do you want to set any upper/lower limits for the parameters?

Convergence How good does the estimate need to be.

Non-linear regression

Each program has its own approach(s) as it attempts to find the optimum solution.

Your best bet is to: Try several different programs if possible. Test each program using the various options available. Try different rearrangements of your model to see what effect it has.

Things are usually OK if the changes above still result is the same basic solution

Actual model

For this model, the goal is to determine the minimum error solution for the following:

RT

b^ V^ M^ h +| s l z f^2 +z f +ln (1 - z f ) = 0

RT =2479. | s =0. V (^) M = molar volume of solvent z f = polymer volume fraction h =( D (^) p - D (^) s )^2 +0.25 8 ^ P (^) p - Ps h^2 +( H (^) p - H (^) s )^2 B D (^) s , Ps , H (^) s - known constants D (^) p , Pp , H (^) p - parameters to be fit

Using Excel’s ‘Solver’

The Solver is a built in non-linear least squares function for Excel. Parameters are held in specific cells that it will alter to find a solution. It tests by seeking a minimize or maximize value held in another ‘cell’ All intermediates must be also be cell functions. Several options are available.

Experimental data Calculated values

We will be minimizing by tracking the sum of squares - that is what is held in the delta2 column

RT b^ V^ M^ h +| s l z f^2 +z f +ln (1 - z f ) = 0

A A

Parameters and constants

Column B contains known constants for the experiment

Column E contains the values to be adjusted - Dp, Pp and Hp. SSE is the sum of squares that will be tested.

Using Excel’s ‘Solver’

Using XLStat Using XLStat

Pred(A1) / A

0

1

2

0 0.5 1 1.5 2 2. Pred(A1)

A