R^2 in Generalized Linear Models

40 Views Asked by At

I am trying to model relationship between predictors and explained variable in R using glm() function. I've found quite good model that gives me satisfactory results.

Is there some way how to compute coefficient of determination $R^2$ in R for GLM? Does it even make sense to consider it for GLM?

I've tried this code but I am not sure that it's correct.

RSS<-sum((fitted(mg)-B$k)^2)
TSS<-sum((B$k-mean(B$k))^2)
R_sq<-1-RSS/TSS

mg is my model and B$k is vector of observations of my dependent variable.

Thanks.