note10_regression

There are a few outliers that stand out for the

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: tter(SIZE), LOGTIME, xaxp=c(0,1,1)) plot(jitter(STATUS), LOGTIME, xaxp=c(0,1,1)) • There is a positive linear relationship between the average number of nesting pairs and the time to extinction. • There are a few outliers that stand out for the general pattern. • For the categorical variables, we use the function jitter in R to see overlapping points. & % ' $ 4 Raven q Rock_dove Skylark q q q 3 Ringed_plover Starling q q q Slide 12 q q q q 2 LOGTIME q q q q q q q q q q q q q q q q 1 q q q q q q q q q q q q q q qq qq q q q q q q q 0 q q q qq q 2 4 6 8 10 12 NESTING & % MATH-440 Linear Regression ' $ 4 q q q q 3 q q q Slide 13 q 2 LOGTIME q q q q q q q q q q qq q q q q q q q q q 1 q q q q q q q q q q q q q q q q q q q q q q q q 0 q q q q q q q 0 q q 1 jitter(SIZE) & % ' $ 4 q q q q 3 q q q Slide 14 2 LOGTIME q q q q q q q qq q q q q 1 q q q q q q q q q q q q q q q q q q q q 0 q q q q q q q q q q q q q q qq q q qq 0 q 1 jitter(STATUS) & % MATH-440 Linear Regression ' $ The regression model is given by: LOGTIMEi = β0 + β1 NESTINGi + β2 SIZEi + β3 STATUSi + εi where the two categorical variables are represented by binary indicator variables. Slide 15 • Let us rst t the standard least-squares model using the function lm in R: fit = lm(LOGTIME ~ NESTING + as.factor(SIZE) + as.factor(STATUS), data=bird) summary(fit) Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 0.43087 0.20706 2.081 0.041870 * NESTING 0.26501 0.03679 7.203 1.33e-09 *** as.factor(SIZE)1 -0.65220 0.16667 -3.913 0.000242 *** as.factor(STATUS)1 0.50417 0.18263 2.761 0.007712 ** & % ' $ Let us now perform Bayesian inference. We can sample (σ 2 , β ) from the joint posterior distribution by • rst drawing σ 2 from the inverse-gamma((n − k )/2, S 2 /2) density Slide 16 • then simulating the vector β from the multivariate normal ˆ density with mean β and variance-covariance matrix (X T X )−1 σ 2 . y = LOGTIME n=length(y) x = as.matrix(cbind(rep(1,n), bird[,3:5])) Vb = solve(t(x)%*%x) betahat = Vb%*%t(x)%*%y S2 = t(y-x%*%betahat)%*%(y-x%*%betahat) & % MATH-440 Linear Regression ' Slide 17 $ library(LearnBayes) T = 10000; k=dim(x)[2] sigma2 = rigamma(T, (n-k)/2, S2/2) beta = matrix(NA, T, k) for(i in 1:T) { beta[i,] = rmnorm(1, betahat, sigma2[i]*Vb) } Let us look at the distributions of the the simulated posterior draws: par(mfrow=c(2,2)) hist(beta[,2], main="NESTING", xlab=expression(beta[1]), prob=T, breaks=50) hist(beta[,3], main="SIZE", xlab=expression(beta[2]), prob=T, breaks=50) hist(beta[,4], main="STATUS", xlab=expression(beta[3]), prob=T,...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online