[R] GLM and WLS

frespider frespider at hotmail.com
Tue Nov 6 03:23:44 CET 2012


Hi 

I am running some simulation in  R after resampling from a huge data set 500
columns and 86759 rows and fit these two model and calculate R-square 
fit <- lm(Y~X,weights = Weights)
bhat <- coef(fit)
Yhat <- X%*%bhat                         
SST <- sum((Y - mean(Y))^2)              
SSE <- sum((Y - Yhat)^2)               
MSE <- SSE/(n-pc)                  
aRsqr <- 1-(((n-1)*SSE)/((n-pc)*SST)) 

and the GLM Model

fitGLM <- glm(Y~X,family=Gamma(link = "log"))

Yhat <-exp( X%*%bhat )
SST <- sum((Y - mean(Y))^2)              
SSE <- sum((Y - Yhat)^2)               
MSE <- SSE/(n-pc)                  
aRsqr <- 1-(((n-1)*SSE)/((n-pc)*SST)) 

I am getting a negative R-square which I don't understand why? Can some one
let me know why and if I can investigate that how I do that.

Thanks



--
View this message in context: http://r.789695.n4.nabble.com/GLM-and-WLS-tp4648531.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list