Advertisement
Guest User

Untitled

a guest
Nov 28th, 2014
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. require(ggplot2)
  2. delta <- 0.0001 #smaller for smoother curves but longer plot times
  3.  
  4. chisq.df <- data.frame(x = seq(from=0.01, to=5, by=delta)) #avoid near 0 due to spike in pdf
  5. chisq.df$pdf <- dchisq(chisq.df$x, df=1)
  6. chisq.df$decile <- floor(10*pchisq(chisq.df$x, df=1) + 1)
  7.  
  8. g <- ggplot(chisq.df, aes(x=x, y=pdf, fill=decile)) + scale_fill_gradient2(midpoint=5.5, guide="none") + theme_bw()
  9. for(n in 1:10) g <- g + geom_ribbon(data=subset(chisq.df, decile == n), aes(ymin=0, ymax=pdf), colour = "black")
  10. print(g)
  11.  
  12. z.df <- data.frame(x = seq(from=-3, to=3, by=delta))
  13. z.df$pdf <- dnorm(z.df$x)
  14. z.df$decile <- floor(10*pnorm(z.df$x) + 1)
  15. g <- ggplot(z.df, aes(x=x, y=pdf, fill=decile)) + scale_fill_gradient2(midpoint=5.5, guide="none") + theme_bw() +xlab("y")
  16. for(n in 1:10) g <- g + geom_ribbon(data=z.df[z.df$decile == n,], aes(ymin=0, ymax=pdf), colour = "black")
  17. print(g)
  18.  
  19. data.df <- data.frame(x=c(seq(from=0, to=6, by=delta)))
  20. data.df$y <- qnorm(pchisq(data.df$x, df=1))
  21. ggplot(data.df, aes(x,y)) + theme_bw() + geom_line()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement