Posted By

daviddalpiaz on 09/10/10


Tagged


Versions (?)

Test


 / Published in: R
 

  1. # read and expand the data
  2. data(g1_part)
  3. data <- expData(g1_part, 2, 3)
  4. #plotCounts(data$count[data$index == 1])
  5.  
  6.  
  7. # get the CV R squared for Poisson linear model
  8. ##R_sq <- iterGlmCV(data)
  9.  
  10.  
  11. # train and predict by Poisson linear model
  12. train.data <- data[data$index < 6, ]
  13. test.data <- data[data$index >= 6, ]
  14. train.glm <- iterGlm(train.data)
  15. ##plotCoef(train.glm, 2, 3)
  16. pred.pref <- exp(glmPred(train.glm, test.data))
  17.  
  18.  
  19. # get predicted counts
  20. pred.count <- getPredCount(test.data, pred.pref)
  21. ##plotCounts(pred.count[data$index == 1])
  22.  
  23.  
  24. # get the R squared
  25. glm.dev <- getDev(pred.count, test.data$count)
  26. null.count <- getNullCount(test.data)
  27. null.dev <- getDev(null.count, test.data$count)
  28. R_sq <- 1 - glm.dev / null.dev

Report this snippet  

You need to login to post a comment.