Processing math: 100%
+ - 0:00:00
Notes for current slide
Notes for next slide

Evaluating Fit Linear Models


1 / 50

Etherpad



https://etherpad.wikimedia.org/p/607-lm-2022

2 / 50

Putting Linear Regression Into Practice with Pufferfish

  • Pufferfish are toxic/harmful to predators

  • Batesian mimics gain protection from predation - why?

  • Evolved response to appearance?

  • Researchers tested with mimics varying in toxic pufferfish resemblance

3 / 50

Question of the day: Does Resembling a Pufferfish Reduce Predator Visits?

4 / 50

Digging Deeper into Regression

  1. Assumptions: Is our fit valid?

  2. How did we fit this model?

5 / 50

You are now a Statistical Wizard. Be Careful. Your Model is a Golem.

(sensu Richard McElreath)

6 / 50

A Case of "Great" versus "Not as Great" Fits...

7 / 50

The Two Fits





8 / 50

Assumptions (in rough descending order of importance)

  1. Validity

  2. Representativeness

  3. Model captures features in the data

  4. Additivity and Linearity

  5. Independence of Errors

  6. Equal Variance of Errors

  7. Normality of Errors

  8. Minimal Outlier Influence

9 / 50

Validity: Do X and Y Reflect Concepts I'm interested In

What if predator approaches is not a good measure of recognition? Or mimics just don't look like fish?

10 / 50

Solution to lack of validity:

Reframe your question! Change your framing! Question your life choices!

11 / 50

Representativeness: Does Your Data Represent the Population?

For example, say this is your result...

12 / 50

But is that all there is to X in nature?

13 / 50

Representativeness: Does Your Data Represent the Population?

What if you are looking at only a piece of the variation in X in your population?

14 / 50

Representativeness: Does Your Data Represent the Population?

How should you have sampled this population for a representative result?

15 / 50

Representativeness: Does Your Data Represent the Population?

It's better to have more variation in X than just a bigger N

16 / 50

Representativeness: Does Your Data Represent the Population?

  • Always question if you did a good job sampling

  • Use natural history and the literature to get the bounds of values

  • If experimenting, make sure your treatment levels are representative

  • If you realize post-hoc they are not, qualify your conclusions

17 / 50

Model captures features in the data

Does the model seem to fit the data? Are there any deviations? Can be hard to see...

18 / 50

Simulating implications from the model to see if we match features in the data

Is anything off?

19 / 50

But what to wolves say to you?

20 / 50

Additivity and Linearity: Should account for all of the variation between residual and fitted values - what you want

21 / 50

Additivity and Linearity: Wolf Problems?

22 / 50

Additivity and Linearity: Wolf Problems?

Solutions: Nonlinear transformations or a better model!

22 / 50

Independence of Errors

  • Are all replicates TRULY independent

  • Did they come from the same space, time, etc.

  • Non-independence can introduce BIAS

    • SEs too small (at the least)
    • Causal inference invalid
  • Incoporate Non-independence into models (many methods)

23 / 50

Equal Variance of Errors: No Pattern to Residuals and Fitted Values

24 / 50

Equal Variance of Errors: What is up with intermediate Wolf Values

25 / 50

Equal Variance of Errors: Problems and Solutions

  • Shapes (cones, footballs, etc.) with no bias in fitted v. residual relationship

  • A linear relationship indicates an additivity problem

  • Can solve with a better model (more predictors)

  • Can solve with weighting by X values, if source of heteroskedasticity known

    • This actually means we model the variance as a function of X
    • ϵi(N,f(xi))
  • Minor problem for coefficient estimates

  • Major problem for doing inference and prediction as it changes error

26 / 50

Normality of errors: Did we fit the error generating process that we observed?

  • We assumed ϵiN(0,σ) - but is that right?

  • Can assess with a QQ-plot

    • Do quantiles of the residuals match quantiles of a normal distribution?
  • Again, minor problem for coefficient estimates

  • Major problem for doing inference and prediction, as it changes error

27 / 50

Equal Variance of Errors: Puffers

28 / 50

Equal Variance of Errors: Wolves underpredict at High Levels

29 / 50

Outliers: Cook's D

30 / 50

Leverage: Cook's D Scaled by Value

31 / 50

Leverage: Cook's D - wolves OK

32 / 50

Everyone worries about outliers, but...

  • Are they real?

  • Do they indicate a problem or a nonlinearity?

  • Remove only as a dead last resort

  • If from a nonlinearity, consider transformation

33 / 50

Assumptions (in rough descending order of importance)

  1. Validity: only you know!

  2. Representativeness: look at nature

  3. Model captures features in the data: compare model v. data!

  4. Additivity and Linearity: compare model v. data!

  5. Independence of Errors: consider sampling design

  6. Equal Variance of Errors: evaluate res-fit

  7. Normality of Errors: evaluate qq and levene test

  8. Minimal Outlier Influence: evaluate Cook's D

34 / 50

Digging Deeper into Regression

  1. Assumptions: Is our fit valid?

  2. How did we fit this model?

  3. How do we draw inference from this model?

35 / 50

So, uh.... How would you fit a line here?

36 / 50

Lots of Possible Lines - How would you decide?

37 / 50

Method of Model Fitting

  1. Least Squares

    • Conceptually Simple
    • Minimizes distance between fit and residuals
    • Approximations of quantities based on frequentist logic
  2. Likelihood

    • Flexible to many models
    • Produces likelihood surface of different parameters
    • Equivalent to LS for Gaussian likelihood
    • Approximations of quantities based on frequentist logic
  3. Bayesian

    • Incorporates prior knowledge
    • Probability for any parameter is likelihood * prior
    • Superior for quantifying uncertainty
    • With "flat" priors, equivalent to least squares/likelihood
    • Analytic or simulated calculation of quantities
38 / 50

Basic Principles of Least Squares Regression

ˆY=β0+β1X+ϵ where β0 = intercept, β1 = slope

Minimize Residuals defined as SSresiduals=(YiˆY)2

39 / 50

Let's try it out!

40 / 50

Analytic Solution: Solving for Slope



b=sxys2x =cov(x,y)var(x)

41 / 50

Analytic Solution: Solving for Slope



b=sxys2x =cov(x,y)var(x)

=rxysysx

41 / 50

Analytic Solution: Solving for Intercept



Least squares regression line always goes through the mean of X and Y

ˉY=β0+β1ˉX



42 / 50

Analytic Solution: Solving for Intercept



Least squares regression line always goes through the mean of X and Y

ˉY=β0+β1ˉX



β0=ˉYβ1ˉX

42 / 50

Least Squares Visualized

43 / 50

Likelihood

  • Flexible to many models
  • Produces likelihood surface of different parameters
  • Equivalent to LS for Gaussian likelihood
  • Approximations of quantities based on frequentist logic
44 / 50

Likelihood

  • Flexible to many models
  • Produces likelihood surface of different parameters
  • Equivalent to LS for Gaussian likelihood
  • Approximations of quantities based on frequentist logic

L=p(Data|parmeters)

44 / 50

Likelihood

  • Flexible to many models
  • Produces likelihood surface of different parameters
  • Equivalent to LS for Gaussian likelihood
  • Approximations of quantities based on frequentist logic

L=p(Data|parmeters)L(θ|D)=dnorm(yi,μ=β0+β1xi,σ)

44 / 50

Likelihood

  • Flexible to many models
  • Produces likelihood surface of different parameters
  • Equivalent to LS for Gaussian likelihood
  • Approximations of quantities based on frequentist logic

L=p(Data|parmeters)L(θ|D)=dnorm(yi,μ=β0+β1xi,σ)Deviance = -2 * Log Likelihood

44 / 50

Likelihood: Minimizing Deviance (Maximizing Likelihood) by Search

Preliminary iteration .. Done
Profiling for parameter (Intercept) ... Done
Profiling for parameter resemblance ... Done

45 / 50

Bayesian

  • Incorporates prior knowledge
  • Probability for any parameter is likelihood * prior
  • Superior for quantifying uncertainty
  • With "flat" priors, equivalent to least squares/likelihood
  • Analytic or simulated calculation of quantities

p(H|D)=p(D|H)p(H)p(D)

46 / 50

Bayes: Creating a Posterior Probability Distribution

47 / 50

Bayes: Creating a Posterior Probability Distribution

Searches p(H|D)=p(D|H)p(H)p(D)

47 / 50

Bayes: Creating a Posterior Probability Distribution

48 / 50

Linear Regression - the Core of Everything

  • Make sure you meet assumptions
    • Don't burn down Prague
  • Many ways to fit
    • We will talk inference later
    • The key is looking at estimated values and their implications
    • Look at precision - do you feel comfortable with inference?
49 / 50

<!--

-->

<!--

-->
50 / 50

Etherpad



https://etherpad.wikimedia.org/p/607-lm-2022

2 / 50
Paused

Help

Keyboard shortcuts

, , Pg Up, k Go to previous slide
, , Pg Dn, Space, j Go to next slide
Home Go to first slide
End Go to last slide
Number + Return Go to specific slide
b / m / f Toggle blackout / mirrored / fullscreen mode
c Clone slideshow
p Toggle presenter mode
t Restart the presentation timer
?, h Toggle this help
Esc Back to slideshow