Regression is a mainstay of ecological and evolutionary data analysis. For example, a disease ecologist may use body size (e.g. a weight from a scale with measurement error) to predict infection. Classical linear regression assumes no error in covariates; they are known exactly. This is rarely the case in ecology, and ignoring error in covariates can bias regression coefficient estimates. This is where model II (aka errors-in variables and measurement errors) regression models come in handy. Here I’ll demonstrate how to construct such a model in a Bayesian framework, where substantive prior knowledge of covariate error facilitates less-biased parameter estimates.
Here’s a quick illustration of the problem: I’ll generate data from a known simple linear regression model, and fit models that ignore or incorporate error in the covariate.
Incorporating error in the covariate: I’m assuming that we have substantive knowledge about covariate measurement represented in the prior for the precision in X. Further, the prior for the true X values reflects knowledge of the distribution of our X value in the population from which the sample was taken.
ggplot(d, aes(x=obsx, obsy))+ geom_abline(aes(intercept=a, slope=b), data=d, color="red", alpha=0.05)+ geom_abline(aes(intercept=a2, slope=b2), data=d2, color="blue", alpha=0.05)+ geom_abline(aes(intercept=alpha, slope=beta), data=parms, color="green", size=1.5, linetype="dashed")+ theme_bw()+ geom_point(shape=1, size=3)+ xlab("X values")+ ylab("Observed Y values")+ ggtitle("Model results with and without modeling error in X")
The dashed green line shows the model that generated the data, i.e. the “true” line. The red lines show the posterior for the naive model ignoring error in X, while the less-biased blue lines show the posterior for the model incorporating error in X.
To leave a comment for the author, please follow the link and comment on his blog: Ecology in silico.