Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. f <- function(toss=1){
  2. x <- sample(1:2, size=toss, replace=TRUE)
  3. y <- sample(1:2, size=toss, replace=TRUE)
  4. return(cbind(x,y))
  5. }
  6. set.seed(2500)
  7. toss_times <- as.data.frame(f(2000))
  8.  
  9. library(plyr)
  10.  
  11. freq <- ddply(toss_times, ~x, summarize,
  12. y1=sum(y==1), y2=sum(y==2))
  13. row.names(freq) <- paste0('x',1:2)
  14. prob_table1 <- freq_table[,-1]/2000
  15. prob_table1
  16.  
  17.  
  18. prob_x <- table(toss_times$x)/2000
  19. prob_y <- table(toss_times$y)/2000
  20. prob_table2 <- outer(prob_x,prob_y,'*')
  21. row.names(prob_table2) <- paste0('x',1:2)
  22. colnames(prob_table2) <- paste0('y',1:2)
  23. prob_table2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement