Watts-College / paf-514-template

https://watts-college.github.io/paf-514-template/
1 stars 0 forks source link

Lab 2 - Do my numbers seem on track, simulation results change after knitting making answers not match, clarification on Question 2.2, and help with part 2 in case it helps anyone else #73

Closed swest235 closed 3 weeks ago

swest235 commented 1 month ago

@castower I believe I have completed the lab - what I think was supposed to be straightforward whooped me a bit. I'd like to make sure my answers are on track (if that is ok) so I can try and fix things before its due tomorrow night.

First Question: Do these outputs track with expected results? Part 1 (5 doors ) show STAYING is about 10% better. Part 2.1 (9 goats, 1 car) show switching is about 1% better. Part 2.2 (8 goats, 2 cars) show switching is about 2% better. Part 2.3 (7 goats, 3 cars) show switching is about 2% better.

Second Question: Silly question, but the outputs vary a little after knitting, do we need to save our outputs for each simulation somehow so after knitting it shows the results we saw in RMD or is the slight variability ok?

Third Question: Question 2.2 asks about the original game - is this referring to the 3 door, 5 door, or 10 door (9 goat, 1 car) game? Not sure what the operational definition of original would be here so I put a response to all, but asked in case anyone else was wondering. Probably overthinking this.

Fourth Question: I found this worked, but wanted to make sure this was the right move regarding the arguments for each differing game. Is this the right way to change game setup by inputting the number of goats and number of cars in the play.game function arguments? So for 2.1 its 9/1, 2.2 would be 8/2, 2.3 is 7/3?

play.game <- function(num.goats = 9, num.cars = 1) 
{

this.game <- create_game( num.goats = num.goats, num.cars = num.cars )
my.initial.pick <- select_door( game=this.game )
opened.door <- open_goat_door( this.game, my.initial.pick )

my.final.pick.stay <- change_door( stay=T, game=this.game, 
                                   opened.door=opened.door, a.pick=my.initial.pick )
my.final.pick.switch <- change_door( stay=F, game=this.game,
                                     opened.door=opened.door, a.pick=my.initial.pick )

game.outcome.stay <- determine_winner( final.pick=my.final.pick.stay, game=this.game )
game.outcome.switch <- determine_winner( final.pick=my.final.pick.switch, game=this.game )

strategy <- c("stay", "switch")
outcome <- c(game.outcome.stay, game.outcome.switch)
game.results <- data.frame(strategy, outcome, stringsAsFactors = F)

return(game.results)
}

play.game()
ClaudiaHebert commented 1 month ago

Hi,

Chiming in to see if I can be helpful with at least some of your questions!

  1. These numbers are roughly what I was getting as well. Although for the 7 goats, 3 cars my simulations are usually showing 3-5%. I was also wondering if the variability matters.

  2. Not sure about this, I didn't do anything special.

  3. I interpreted this as the original game meaning 3 doors with 2 goats and 1 car, though I could be incorrect.

  4. I did essentially the same thing. The only difference was that I made my wrapper function play_game <- function(num.goats, num.cars) and then entered the inputs each time I called the play_game() function. (I.e. - if I wanted 8 goats and 2 cars I would have play_game(8,2). I think the only difference between our versions is that you put in default arguments of 9 and 1 whereas I don't have defaults. However I could be wrong and it's possible that you're having to re-create the wrapper function with the corresponding input every time before calling play_game(). I'd love to know if that's the case.

Hope this helps a bit!

castower commented 1 month ago

Hello @swest235,

  1. Yes, those are on track for expected results

  2. If you would like to ensure that your output is constant from when you run it to when you knit, you can use set.seed() before running your play_game so that your sample is reproducible (https://www.digitalocean.com/community/tutorials/sample-in-r#taking-samples-using-the-function-set-seed). The "seed" can be any number so you can use the number of your iterator to ensure it's the same set of numbers, but a different number for each game:

For example:

for( i in 1:10000 )  # iterator
{
  set.seed(i)
  game.outcome <- play_game() 
}
  1. The original game is referring to the 3 door version, but any comparison will be accepted.

  2. Yes, that's perfect.

Let me know if you have any other questions!

swest235 commented 1 month ago

@castower @ClaudiaHebert Thank you both for the replies!