Last active
August 29, 2015 14:16
-
-
Save haroldkyle/807867c349e8af75ecd9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# namespace gl | |
gl <- new.env() | |
# # of trials to run | |
gl$trials <- 20000 | |
# profits (price minus costs) and their related probabilities | |
gl$entreeProfit <- c(9,7.5,5.5,4) | |
gl$entreeProbability <- c(0.25,0.35,0.3,0.1) | |
# empty vector for trial data | |
gl$results <- c() | |
# iterate through trials and fill data frame row by row | |
for(i in 1:gl$trials){ | |
profit <- sample(gl$entreeProfit,1,TRUE,gl$entreeProbability) | |
meals <- rnorm(1,3000,1000) | |
labor <- runif(1,5040,6860) | |
gl$results <- rbind(gl$results, profit * meals - labor - 3995) | |
} | |
# tidy up global environment | |
remove(profit,meals,labor,i) | |
summary(gl$results) | |
hist(gl$results) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment