Andrew Schuh
2007-May-09 20:09 UTC
[R] generalized least squares with empirical error covariance matrix
I have a bayesian hierarchical normal regression model, in which the regression coefficients are nested, which I've wrapped into one regression framework, y = X %*% beta + e . I would like to run data through the model in a filter style (kalman filterish), updating regression coefficients at each step new data can be gathered. After the first filter step, I will need to be able to feed the a non-diagonal posterior covariance in for the prior of the next step. "gls" and "glm" seem to be set up to handle structured error covariances, where mine is more empirical, driven completely by the data. Explicitly solving w/ "solve" is really sensitive to small values in the covariance matrix and I've only been able to get reliable results at the first step by using weighted regression w/ lm(). Am I missing an obvious function for linear regression w/ a correlated prior on the errors for the updating steps? Thanks in advance for any advice.
Roy Mendelssohn
2007-May-09 20:16 UTC
[R] generalized least squares with empirical error covariance matrix
Look at "DLM". it can do bayesian dynamic linear models, ie. the bayes equivalent of kalman filtering. -Roy M. On May 9, 2007, at 1:09 PM, Andrew Schuh wrote:> I have a bayesian hierarchical normal regression model, in which the > regression coefficients are nested, which I've wrapped into one > regression framework, y = X %*% beta + e . I would like to run data > through the model in a filter style (kalman filterish), updating > regression coefficients at each step new data can be gathered. After > the first filter step, I will need to be able to feed the a non- > diagonal > posterior covariance in for the prior of the next step. "gls" and > "glm" > seem to be set up to handle structured error covariances, where > mine is > more empirical, driven completely by the data. Explicitly solving w/ > "solve" is really sensitive to small values in the covariance > matrix and > I've only been able to get reliable results at the first step by using > weighted regression w/ lm(). Am I missing an obvious function for > linear regression w/ a correlated prior on the errors for the > updating > steps? Thanks in advance for any advice. > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting- > guide.html > and provide commented, minimal, self-contained, reproducible code.********************** "The contents of this message do not reflect any position of the U.S. Government or NOAA." ********************** Roy Mendelssohn Supervisory Operations Research Analyst NOAA/NMFS Environmental Research Division Southwest Fisheries Science Center 1352 Lighthouse Avenue Pacific Grove, CA 93950-2097 e-mail: Roy.Mendelssohn at noaa.gov (Note new e-mail address) voice: (831)-648-9029 fax: (831)-648-8440 www: http://www.pfeg.noaa.gov/ "Old age and treachery will overcome youth and skill."