Advertisement
Guest User

Untitled

a guest
Sep 25th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. library(ResourceSelection)
  2. n <- 500; chisqs <- c()
  3. for (i in 1:10000) {
  4. x <- rnorm(n)
  5. p <- plogis(0.1+0.5*x)
  6. y <- rbinom(n,1,p)
  7. x2 <- hoslem.test(y,p)$statistic
  8. chisqs <- cbind(chisqs,x2);
  9. }
  10. h <- hist(chisqs,50)
  11. xs <- seq(0,25,0.01)
  12. ys <- dchisq(xs,df=10)
  13. lines(xs,ys*h$counts/h$density)
  14.  
  15. library(ResourceSelection)
  16. n <- 500; chisqs <- c()
  17. for (i in 1:10000) {
  18. x <- rnorm(n)
  19. p <- plogis(0.1+0.5*x)
  20. y <- rbinom(n,1,p)
  21. fit <- glm(y~x)
  22. x2 <- hoslem.test(y,fitted(fit))$statistic
  23. chisqs <- cbind(chisqs,x2);
  24. }
  25. h <- hist(chisqs,50)
  26. xs <- seq(0,25,0.01)
  27. ys <- dchisq(xs,df=8)
  28. lines(xs,ys*h$counts/h$density)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement