Johannes Radinger <JRadinger@...> writes: > thank you all for you tips with predict, predict.lm etc. > >From summary(lm-model), I can get the Estimate and the Standard > Error for intercept and slopes. With confint I can get confidence > intervals (?) for these parameters for different levels. > > I want to calculate it by hand, rather then by using R's predict > function, due to some reasons: > > 1) I want to get the mathematical background > 2) I want to use it in a model outside of grass (python-model, and > I don't want to use a direct interaction python-R) > 3) I want to calculate it with simple > programming languages (e.g. simplest form of basic etc.) > > In wikipedia it says that it is possible to > calculate the prediction interval from the standard error of the > parameters. So how is that done exactly? Can anyone guide me > to the formula? Or is it just > > Y=b+Intercept + (a1+SE(a1))*X1+(a2+SE(a2)*X2 > (of course with all variations in plus and minus SE)? > > Your help is greatly appreciated! > > /johannes >
[snip] You need to take the covariance of the parameters into account. Suppose you want to calculate the prediction interval for values X1=a1, X2=a2. Form a vector X=c(1,a1,a2) (the first term is for the intercept). If you (matrix) multiply this by your parameter vector beta (X %*% beta), i.e. beta_0 + beta_1*a1+beta_2*a2 you get your predicted value. If you have variance-covariance matrix V for the intercept and slopes (a 3x3 symmetric matrix) then the variance of the prediction is X %*% V %*% X^T. Code following this approach can be found at http://glmm.wikidot.com/faq . _______________________________________________ R-sig-ecology mailing list R-sig-ecology@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-ecology