52

Recap and fill in the blanks · 2012. 8. 21. · Mixed effects models Can rearrange a linear hierarchical model in terms of a fixed effects linear model and one or more random effects

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Recap and fill in the blanks · 2012. 8. 21. · Mixed effects models Can rearrange a linear hierarchical model in terms of a fixed effects linear model and one or more random effects

Recap and fill in the blanks

Page 2: Recap and fill in the blanks · 2012. 8. 21. · Mixed effects models Can rearrange a linear hierarchical model in terms of a fixed effects linear model and one or more random effects

Course Overview

� Section 1: Basics

� Probability, distribution, theory/methods for point estimation in Likelihood and Bayes

� Section 2: Core

� Interval estimation

� Model comparison

� Relaxing the assumptions of linear models

� Section 3: Advanced applications

Second Exam on Friday April 2nd

Page 3: Recap and fill in the blanks · 2012. 8. 21. · Mixed effects models Can rearrange a linear hierarchical model in terms of a fixed effects linear model and one or more random effects

Course Goals

� Acquire a �toolbox� of basic flexible techniques

� Gain experience applying these tools (LAB)

� Be able to read and evaluate statistics used in the biological literature

� Be able to understand and evaluate new statistics

� Be able to relax the assumptions of existing methods or devise new models tailored to the problem at hand

Page 4: Recap and fill in the blanks · 2012. 8. 21. · Mixed effects models Can rearrange a linear hierarchical model in terms of a fixed effects linear model and one or more random effects

SOME OF THEIR RULES CAN BE BENT, OTHERS

CAN BE BROKEN

Page 5: Recap and fill in the blanks · 2012. 8. 21. · Mixed effects models Can rearrange a linear hierarchical model in terms of a fixed effects linear model and one or more random effects

Experimental Design

� Traditional design

� Minimize sources of variability

� Balanced Replication

� Simple treatments

� Classical ANOVA and Regression stats

� Popperian falsification

� High power

� Limited generality

� �Does this matter in the real world�

Page 6: Recap and fill in the blanks · 2012. 8. 21. · Mixed effects models Can rearrange a linear hierarchical model in terms of a fixed effects linear model and one or more random effects

Experimental Design

� �Real world� experiments

� Real world is variable

� Gain a broader scope of reference

� Loose power

� Multiple alternative hypotheses

� Need a statistical framework that can account for the complexity and variability of the real world

Page 7: Recap and fill in the blanks · 2012. 8. 21. · Mixed effects models Can rearrange a linear hierarchical model in terms of a fixed effects linear model and one or more random effects

Probability Theory

� Basis of both Likelihood and Bayesian perspectives

� Conditional probability

� Random variables � have a PDF

� Likelihood P( data | model )

� Parameters fixed, data random

� Bayes' posterior P( model | data )

� Data fixed, parameters random

Page 8: Recap and fill in the blanks · 2012. 8. 21. · Mixed effects models Can rearrange a linear hierarchical model in terms of a fixed effects linear model and one or more random effects

Probability Density Functions

� Must integrate to 1

� Choose based on

� Type of X:

� continuous or discrete

� Numeric, ordinal, categorical

� Range of X

� Lower bound, upper bound

� Shape of distribution

� Conjugacy

X~f ���

Page 9: Recap and fill in the blanks · 2012. 8. 21. · Mixed effects models Can rearrange a linear hierarchical model in terms of a fixed effects linear model and one or more random effects

Adding flexibility

� Truncation (don't forget to re-normalize)

� Mixtures

� Based on conditionals

� Zero-inflation

� P(X | event) * P(event)

� Hierarchical structure

� P(X|�1) * P(�1 | �2)

� Each stage can incorporate process models

� P(cone) = P(cone = f(size) | fecund) * p(fecund = f(size))

Page 10: Recap and fill in the blanks · 2012. 8. 21. · Mixed effects models Can rearrange a linear hierarchical model in terms of a fixed effects linear model and one or more random effects

Bayes' Theorem

P ���y � =P � y���P ���

P � y �

=P � y���P ���

���

P � y���P ���d �

Likelihood PriorPosterior

Page 11: Recap and fill in the blanks · 2012. 8. 21. · Mixed effects models Can rearrange a linear hierarchical model in terms of a fixed effects linear model and one or more random effects

ThinkConditionally

Page 12: Recap and fill in the blanks · 2012. 8. 21. · Mixed effects models Can rearrange a linear hierarchical model in terms of a fixed effects linear model and one or more random effects

Data model

� Choose PDF that is appropriate for the data

� Can accommodate more complex structures to observation errors

� Errors in Variables: x(o) ~ g(x | �x)

� e.g. Lab 9: TDR as a proxy for soil moisture

� Observation error in y: y(o) ~ h(y | �y)

Page 13: Recap and fill in the blanks · 2012. 8. 21. · Mixed effects models Can rearrange a linear hierarchical model in terms of a fixed effects linear model and one or more random effects

Process Model

� Mathematical statements of our hypotheses

� What most people think of as �modeling�

� Usually deterministic

� Conditioned on the value for the parameters, computation will always give the same answer

� Usually used to give E[y]

� There is nothing sacred about linear models

� You will rarely find a theory that looks like linear regression

� Consider asymptotics

Page 14: Recap and fill in the blanks · 2012. 8. 21. · Mixed effects models Can rearrange a linear hierarchical model in terms of a fixed effects linear model and one or more random effects

Parameter Model

� In the Bayesian perspective, all parameters need priors

� Don't forget the data model! (e.g. �2)

� In latent variable problems, state variables are unknowns and thus need priors

� In hierarchical models, the parameter models are more complex and have free parameters

� Require hyperpriors

Page 15: Recap and fill in the blanks · 2012. 8. 21. · Mixed effects models Can rearrange a linear hierarchical model in terms of a fixed effects linear model and one or more random effects

Priors

� Should be proper (integrate to 1), cannot make inference from improper posteriors

� Considerations for PDFs

� Range, shape, etc.

� Mixtures/truncation are permissible

� Logical relationships are permissible (e.g. order)

� When applied, the prior parameters must be specified and stated explicitly

� Must be specified independent of DATA

� Updatable

Page 16: Recap and fill in the blanks · 2012. 8. 21. · Mixed effects models Can rearrange a linear hierarchical model in terms of a fixed effects linear model and one or more random effects

Latent variables

� Sometimes the state variables in a system are

� Unobservable

� Observed with error

� Inferred from proxy data

� Need to be estimated

� Need to integrate over their uncertainty

� Don't ignore the uncertainty in calibration curves

� Don't just interpolate, average, bin, smooth, transform, etc.

Page 17: Recap and fill in the blanks · 2012. 8. 21. · Mixed effects models Can rearrange a linear hierarchical model in terms of a fixed effects linear model and one or more random effects

Linear model: y = Xb + �

� Data model:

� Depends on characteristics of y

� Continuous, discrete, bound over a range, boolean, categorical, circular, etc.

� Process model: Xb or link(Xb)

� Parameter model:

� b is almost always continuous

� Regardless of whether X is cont/disc, bound, etc.

Page 18: Recap and fill in the blanks · 2012. 8. 21. · Mixed effects models Can rearrange a linear hierarchical model in terms of a fixed effects linear model and one or more random effects

When X isn't continuous

� Discrete: Usually treated the same

� Categorical:

� Nominal:

� Design matrix of indicator variables (0,1)

� Equivalent to ANOVA

� Identifiability

� n-1 columns with one group as the REFERENCE group

� OR drop intercept term

� Ordinal:

� Similar to Nominal but may build ORDER restrictions into

MLE / prior for �

Page 19: Recap and fill in the blanks · 2012. 8. 21. · Mixed effects models Can rearrange a linear hierarchical model in terms of a fixed effects linear model and one or more random effects

Assumptions of Linear Model

� Homoskedasticity Model variance

� No error in X variables Errors in variables

� No missing data Missing data model

� Normally distributed error GLM

� Residual error in Y variables is measurement error

� Observations are independent

� Linearity Nonlinear models

Hierarchical Models

Page 20: Recap and fill in the blanks · 2012. 8. 21. · Mixed effects models Can rearrange a linear hierarchical model in terms of a fixed effects linear model and one or more random effects

Heteroskedasticity

1) Transform the data

1) Pro: No additional parameters

2) Cons: No longer modeling the original data, likelihood & process model have different meaning, backtransformation non-trivial (Jensen's Inequality)

2) Model the variance

1) Pro: working with original data and model, no tranf.

2) Con: additional process model and parameters (and priors)

Page 21: Recap and fill in the blanks · 2012. 8. 21. · Mixed effects models Can rearrange a linear hierarchical model in terms of a fixed effects linear model and one or more random effects

y~N �12 x ,��1�2 x �2�

Page 22: Recap and fill in the blanks · 2012. 8. 21. · Mixed effects models Can rearrange a linear hierarchical model in terms of a fixed effects linear model and one or more random effects

Errors in Variables

�y~N �X � , 2�

Data Model

Process Model

Parameter Model

Y

� , �

X0,V

x�

0,V� s

1,s

2

X(o)

X

x�o�~N �x ,�2�

Page 23: Recap and fill in the blanks · 2012. 8. 21. · Mixed effects models Can rearrange a linear hierarchical model in terms of a fixed effects linear model and one or more random effects
Page 24: Recap and fill in the blanks · 2012. 8. 21. · Mixed effects models Can rearrange a linear hierarchical model in terms of a fixed effects linear model and one or more random effects

Missing Data Model

�y~N �X � , 2�

Data Model

Process Model

Parameter Model

Y

� , �

X0,V

x�

0,V� s

1,s2

X

Xmis

Page 25: Recap and fill in the blanks · 2012. 8. 21. · Mixed effects models Can rearrange a linear hierarchical model in terms of a fixed effects linear model and one or more random effects
Page 26: Recap and fill in the blanks · 2012. 8. 21. · Mixed effects models Can rearrange a linear hierarchical model in terms of a fixed effects linear model and one or more random effects

ASSUMPTION!!

� Missing data models assume that the data is missing at random

� If data is missing SYSTEMATICALLY it can not be estimated

Page 27: Recap and fill in the blanks · 2012. 8. 21. · Mixed effects models Can rearrange a linear hierarchical model in terms of a fixed effects linear model and one or more random effects

Generalized Linear Models

� Allows for alternate PDFs to be used in likelihood

� Typically a link function is used to relate linear model to PDF

� Can use most any function as a link function but may only be valid over a restricted range

Distribution Link Name Link Function Mean Function

Normal Identity

Poisson Log

Binomial

Multinomial

Xb = � � = Xb

Xb = ln(�� � = exp(Xb)

LogitXb=ln � �

1�� � �=exp �Xb�

1exp�Xb�

Page 28: Recap and fill in the blanks · 2012. 8. 21. · Mixed effects models Can rearrange a linear hierarchical model in terms of a fixed effects linear model and one or more random effects

If you're response variable is

� Boolean (0/1, True/False, Present/Absent)

� Bernoulli likelihood (logistic regression)

� Count data

� Poisson or Negative Binomial regression

� Categorical data

� Multinomial likelihood (cumulative logistic)

� Continuous but > 0

� Lognormal, exponential, or gamma likelihood

� Proportion (0,1 continuous)

� Beta, Logit-normal, truncated normal

Page 29: Recap and fill in the blanks · 2012. 8. 21. · Mixed effects models Can rearrange a linear hierarchical model in terms of a fixed effects linear model and one or more random effects

Hierarchical Models

Common mean

Y1

Y3

Y2

�2�3

�1

Independent

Y1

Y3

Y2

�1�

2

Y1

Y3

Y2

�3

Hierarchical

Page 30: Recap and fill in the blanks · 2012. 8. 21. · Mixed effects models Can rearrange a linear hierarchical model in terms of a fixed effects linear model and one or more random effects

Hierarchical Models

� Model variability in the parameters of a model

� Partition variability more explicitly into multiple terms

� Borrow strength across data sets

Page 31: Recap and fill in the blanks · 2012. 8. 21. · Mixed effects models Can rearrange a linear hierarchical model in terms of a fixed effects linear model and one or more random effects

Hierarchical Models

Data Model

Process Model

Parameter Model

Y1 ... Y

k ... Y

n

�1

�k �

n

Hyperparameters

�,�2

m0,V� t

1,t

2

s1,s

2

�2

Page 32: Recap and fill in the blanks · 2012. 8. 21. · Mixed effects models Can rearrange a linear hierarchical model in terms of a fixed effects linear model and one or more random effects

Mixed effects models

� Can rearrange a linear hierarchical model in terms of a fixed effects linear model and one or more random effects with mean 0

� This works non-normal likelihoods and is referred to as Generalized Linear Mixed Models (GLMM)

Y k~N �X �k , 2�

�k~N �0,�2�

Page 33: Recap and fill in the blanks · 2012. 8. 21. · Mixed effects models Can rearrange a linear hierarchical model in terms of a fixed effects linear model and one or more random effects

The Devil's in the Details

� Example: Measured the growth of seedling i in plot j in year t for species s = g

i,j,t,s

� gi's are NOT independent

� Would want to consider how i, j, t, and s affect g

� Which are fixed effects? Individual-level covariates?

� Which are random effects? Hierarchical covariates?

� Spatial, temporal, or phylogenetic autocorrelation?

The Details are in the Subscripts

The Blue Devils are in the Final Four

Page 34: Recap and fill in the blanks · 2012. 8. 21. · Mixed effects models Can rearrange a linear hierarchical model in terms of a fixed effects linear model and one or more random effects

Assumptions of Linear Model

� Homoskedasticity Model variance

� No error in X variables Errors in variables

� No missing data Missing data model

� Normally distributed error GLM

� Residual error in Y variables is measurement error

� Observations are independent

� Linearity Nonlinear models

Hierarchical Models

Page 35: Recap and fill in the blanks · 2012. 8. 21. · Mixed effects models Can rearrange a linear hierarchical model in terms of a fixed effects linear model and one or more random effects

Which techniques work where

� All work in Bayesian

� Straightforward in Likelihood

� Heteroskedasticity

� GLM & simple mixed models (GLMM)

� Nonlinear

� Difficult to impossible in Likelihood

� Complex Hierarchical models

� Errors in variables / Latent variables

� Missing data

Page 36: Recap and fill in the blanks · 2012. 8. 21. · Mixed effects models Can rearrange a linear hierarchical model in terms of a fixed effects linear model and one or more random effects

Other Common Errors

� Forgetting about Jensen's Inequality

� Transformations, non-linear models

� Treating �random� quantities like fixed numbers

� Treating regression parameters like data

� Ratios

� Prediction without uncertainty statements

� Work as close to the raw data as possible

� Log + 1 transform of zero-count data

Page 37: Recap and fill in the blanks · 2012. 8. 21. · Mixed effects models Can rearrange a linear hierarchical model in terms of a fixed effects linear model and one or more random effects

Notational equivalence

Y~N �X , 2�

Y=X ��~N �0, 2�

�=X Y~N �� , 2�

N �Y�X , 2�

Page 38: Recap and fill in the blanks · 2012. 8. 21. · Mixed effects models Can rearrange a linear hierarchical model in terms of a fixed effects linear model and one or more random effects

Linking graphs, equations, and code

Data Model

Process Model

Parameter Model

Y

� , �2

�0,V� s

1,s

2

X

�y~N �X � , 2��~N �B0 ,V �

2~IG �s1, s2�

model{ mu ~ dnorm(0,0.001) sigma ~ dgamma(0.001,0.001) for(i in 1:n){ x[i] ~ dnorm(mu[i],sigma) } }

Page 39: Recap and fill in the blanks · 2012. 8. 21. · Mixed effects models Can rearrange a linear hierarchical model in terms of a fixed effects linear model and one or more random effects

Linking Full Posterior & Conditionals

�y~N �X � , 2��~N �B0 ,V �

2~IG �s1, s2�

p �� , 2�X ,Y ��N �Y�X � , 2�×

N ���B0 ,V � IG � 2�s1, s2�

�~N ��y�X � , 2�N �B0 ,V �

2~N ��y�X � , 2� IG � 2�s1, s2�

Page 40: Recap and fill in the blanks · 2012. 8. 21. · Mixed effects models Can rearrange a linear hierarchical model in terms of a fixed effects linear model and one or more random effects

Evaluating Problems

� Problem:

I have count data that comes from different sites. Package XX can do Poisson regression and Package YY can do random effects but I can't find a package that does both

� Solution?

Page 41: Recap and fill in the blanks · 2012. 8. 21. · Mixed effects models Can rearrange a linear hierarchical model in terms of a fixed effects linear model and one or more random effects

Evaluating Analyses

� Errors?

� Alternatives?

Page 42: Recap and fill in the blanks · 2012. 8. 21. · Mixed effects models Can rearrange a linear hierarchical model in terms of a fixed effects linear model and one or more random effects

Methods

� Likelihood

� Finding MLE

� Finding parameter and model CI/PI

� Comparing models

� Bayes

� Finding posterior � gives parameter CI, var, etc.

� Model CI/PI

� Comparing models

Page 43: Recap and fill in the blanks · 2012. 8. 21. · Mixed effects models Can rearrange a linear hierarchical model in terms of a fixed effects linear model and one or more random effects

Finding The MLE

� Write Likelihood

� Express as negative log likelihood

� Analytical

� Take derivative wrt each parameter

� Set each to 0, solve for full set of parameters

� Numerical

� Use numerical algorithm to find minimum

Page 44: Recap and fill in the blanks · 2012. 8. 21. · Mixed effects models Can rearrange a linear hierarchical model in terms of a fixed effects linear model and one or more random effects

Likelihood CI

� Parameter

� Likelihood profile: Deviance ~ chisq

� Fisher Information:

� Bootstrap

� Parametric

� Nonparametric

� Model CI and PI

� Bootstrap

� Variance Decomposition

var [ f �x �]�� � � f��i ��� f�� j �cov [�i ,� j]

I=�d2

ln L ���

d�2 ��ML

se�=1

�� I �

Page 45: Recap and fill in the blanks · 2012. 8. 21. · Mixed effects models Can rearrange a linear hierarchical model in terms of a fixed effects linear model and one or more random effects

Bootstrap

� Monte Carlo method (numerical)

� Based on idea of generating parameter distribution based on large number of replicate data sets that are the same size as original (data random)

� Two variants

� Parametric: pseudodata

� Nonparametric: resample data

Page 46: Recap and fill in the blanks · 2012. 8. 21. · Mixed effects models Can rearrange a linear hierarchical model in terms of a fixed effects linear model and one or more random effects

Non-parametric bootstrap

� Draw a replicate data set by resampling from the original data

� Fit parameters to resample

� Repeat procedure n times

� Estimate parameter CI based on sample quantiles

� Estimate parameter std error as sample s.d.

Page 47: Recap and fill in the blanks · 2012. 8. 21. · Mixed effects models Can rearrange a linear hierarchical model in terms of a fixed effects linear model and one or more random effects

Parametric bootstrap

� Based on parameters fit to original data set generate pseudodata with same dist'n

� Fit parameters to resample

� Repeat procedure n times

� Estimate parameter CI based on sample quantiles

� Estimate parameter std error as sample s.d.

Page 48: Recap and fill in the blanks · 2012. 8. 21. · Mixed effects models Can rearrange a linear hierarchical model in terms of a fixed effects linear model and one or more random effects

Numerical Methods for Bayes: Random samples from the posterior

� Approximate PDF with the histogram

� Performs Monte Carlo Integration

� Allows all quantities of interest to be calculated from the sample (mean, quantiles, var, etc)

TRUE Sample

mean 5.000 5.000

median 5.000 5.004

var 9.000 9.006

Lower CI -0.880 -0.881

Upper CI 10.880 10.872

Page 49: Recap and fill in the blanks · 2012. 8. 21. · Mixed effects models Can rearrange a linear hierarchical model in terms of a fixed effects linear model and one or more random effects

Model Intervals

� Bayesian model CI and PI were generated from quantiles of model predictions from MCMC

� CI: parameter uncertainty

� PI: parameter + data uncertainty (pseudodata)

� The simplest Frequentist CI and PI is based on the bootstrap

� Implementation is identical except use Bootstrap parameter sample rather than MCMC sample

Page 50: Recap and fill in the blanks · 2012. 8. 21. · Mixed effects models Can rearrange a linear hierarchical model in terms of a fixed effects linear model and one or more random effects
Page 51: Recap and fill in the blanks · 2012. 8. 21. · Mixed effects models Can rearrange a linear hierarchical model in terms of a fixed effects linear model and one or more random effects

Likelihood: Model Selection

� Deviance = -2 ln(L)

� Likelihood Ratio Test

� Nested Models

� �Deviance ~ chisq(�number of parameters)

� Gives a p-value

� AIC

� AIC = Deviance + 2*p

� Lowest score wins

Page 52: Recap and fill in the blanks · 2012. 8. 21. · Mixed effects models Can rearrange a linear hierarchical model in terms of a fixed effects linear model and one or more random effects

Bayesian Model Selection

� Predictive Loss = P + G

� Lowest score �wins�

D ����=�2lnL� y����

D ���=� D ��i�/ng

DIC=2D ����D ����

� var [ yrep ]� �E [ yrep]� yobs�2