2
$\begingroup$

I have a 3x3 contingency table, and I tried fitting Poisson GLM in R and calculated the Pearson residuals from it then I cross checked the value by calculating the same manually.

Here the fitted value from the model is the same as the expected value which we get from marginals, but Pearson residual differs.

Example:

data<-c(0,1,2,2,0,8,8,13,16)

out<-gl(3,1,9)

treat<-gl(3,3)

model<-glm(data~out+treat,family=poisson())


model$fitted.values


[1] 0.6    0.84    1.56    2     2.8     5.2    7.4    10.36     19.24

resid(model,type="pearson")

The result of Pearson residual from the above code is different from the results obtained when using the formula (O-E)^2/E from the table.

Why is the difference occurs when the fitted value is same as expected value?

Please clarify my doubt.. Is fitted value is same as expected value?

Thanks in Advance

$\endgroup$
1
$\begingroup$

The formula (O-E)^2/E you give is for the squared Pearson residuals. With (O-E)/E$^{1/2}$ or:

(data-model$fitted.values)/sqrt(model$fitted.values)

You can obtain the same results as with the built-in function. The fitted values is indeed the expected value according to the model.

$\endgroup$
  • $\begingroup$ ! Also I have another doubt. could you please clarify? When I use zeroinflated poisson model for the same matrix, it showing error in solve.default(as.matrix(fit$hessian)) : Lapack routine dgesv: system is exactly singular: U[8,8] = 0. I also extracted the fitted value from this and when I calculate Pearson residual it again showing differently. What am I doing wrong? $\endgroup$ – Sri Priya Sep 4 '18 at 5:15
  • $\begingroup$ Remember to accept the answer when it answers your question. What kind of zero-inflated model did you fit? Perhaps ask a new question. My guess is that you are trying to fit 3 parameters for the zero component, while you only have 2 zero values. Finally, how can you extract fitted values if the model does not fit? $\endgroup$ – Knarpie Sep 4 '18 at 8:18
  • $\begingroup$ I don't have any idea about inflated model. I m just doing a trial and error in learning modelling part. I m wondering what extent is excess zero? can we use inflated model for the presence of two zeroes? And I m not interested in getting model fit actually here. I m concentrating only on residuals, that's why I need fitted values $\endgroup$ – Sri Priya Sep 4 '18 at 10:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.