Advertisement
Guest User

Untitled

a guest
Apr 19th, 2015
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. # namespace gl
  2. gl <- new.env()
  3.  
  4. # # of trials to run
  5. gl$trials <- 20000
  6.  
  7. # profits (price minus costs) and their related probabilities
  8. gl$entreeProfit <- c(9,7.5,5.5,4)
  9. gl$entreeProbability <- c(0.25,0.35,0.3,0.1)
  10.  
  11. # empty vector for trial data
  12. gl$results <- c()
  13.  
  14. # iterate through trials and fill data frame row by row
  15. for(i in 1:gl$trials){
  16. profit <- sample(gl$entreeProfit,1,TRUE,gl$entreeProbability)
  17. meals <- rnorm(1,3000,1000)
  18. labor <- runif(1,5040,6860)
  19. gl$results <- rbind(gl$results, profit * meals - labor - 3995)
  20. }
  21.  
  22. # tidy up global environment
  23. remove(profit,meals,labor,i)
  24.  
  25. summary(gl$results)
  26. hist(gl$results)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement