Advertisement
Guest User

Untitled

a guest
May 4th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. dat <- data.frame(Response=c(rlnorm(10, 2.9, 0.3), rlnorm(14, 2.88, 0.38), rlnorm(19, 2.44, 0.08)),TestNum=rep(c(1,4,9), times=c(10,14,19)))
  2. dat$TestNum<-factor(dat$TestNum)
  3. dat
  4.  
  5. dat_fit1 <- with(dat,
  6. by(dat[,1], TestNum, fitdist, "lnorm"))
  7. dat_fit2 <-t(sapply(dat_fit1, coef))
  8.  
  9. draw_dat <- with(dat,
  10. by(dat[,1], TestNum, function(x){
  11. out<-replicate(1000, rlnorm(150, meanlog=dat_fit2[,1], sdlog=dat_fit2[,2]), simplify=FALSE)}))
  12.  
  13. perce0.5<-rapply(draw_dat, quantile, probs=0.5, classes = "numeric", how = "replace")
  14. perce0.5<-do.call(rbind, perce0.5)
  15. perce0.5<-matrix(unlist(perce0.5), nrow(perce0.5), dimnames = dimnames(perce0.5))
  16.  
  17. mm0.5 <-rowMeans(perce0.5)
  18. mlu0.5<- apply(perce0.5, 1, quantile, probs = c(0.025, 0.975))
  19. mlu<-t(rbind(mm0.5, mlu0.5))
  20. mlu
  21.  
  22. mm0.5 2.5% 97.5%
  23. 1 15.61274 14.25022 17.06212
  24. 4 15.51227 14.15273 16.95342
  25. 9 15.51304 14.17514 16.96741
  26.  
  27. for(i in 1:n) plot(dat_fit1[[2]])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement