Open lindaalvarez opened 2 weeks ago
@lindaalvarez
You'll have to decide how you would like to evaluate your if statement in step 4.
The 100 envelopes example uses switch_choice == "STAY".
Your current change_door() function is expecting the "stay" variable and should check if stay == T.
You can either adjust the if statement section to use the stay variable or change your function input.
@castower So Should I go back and start the game store the answers like the 100 envelope lap does? I'm not quite understanding, I changed my choices to stay and i'm still getting an Error: object 'final.door' not found after this code:
change_door <- function( stay=T, opened.door, a.pick )
my.final.pick <- doors [-my.initial.pick] my.final.pick<- final.door[-open_goat_door]
if (toupper(switch_choice) == "STAY") { out <- my.final.pick } else { out <- doors[my.initial.pick] }
return( final.pick ) # number between 1 and 3
}
@lindaalvarez
First, you'll need to define open_goat_door. Thus, you need to make sure you've saved the number of the opened goat door to this variable.
Then you will need to remove both the contestant's choice and the opened goat door from the door selection options (which should be 1, 2, 3).
So, for example, if the contestant picked door number 1 and the host opened door number 2 as the open_goat_door then only door number 3 should be left.
If the contestant switches, then they will now have door number 3/the remaining prize. If they do not switch they will keep door 1/their original prize.
Finally, update your function input to match your if statement:
So if you keep stay as the variable, your input will be the following:
function( stay=T, opened.door, a.pick )
If you use switch_choice as the variable it will be the following:
function( switch_choice, opened.door, a.pick )
I went ahead and did the steps of removing the contestants' choice as well as the goat door but now I'm having issues with saving the host choice. Attached are screenshots of the errors I am getting as well as my code for eliminating player's choice and saving the host choice. @castower
select_host_choice <- function(doors, player_choice) {
remainding_door <- doors[-player_choice]
goat_door <- which(remaining_door == "goat")
host_choice <- c(host_choice)
host_choice <- sample(goat_door, size =1)
return(host_choice) }
### Now We Need To Save The Host Choice
```{r, fig.height=6, fig.width=7, echo=F}
host_choice <- select_host_choice(doors, player_choice)
host_choice
# test it
this.game <- create_game()
this.game
my.initial.pick <- select_contestant_door()
my.initial.pick
select_host_choice( this.game, my.initial.pick )
@castower I went ahead and restarted the project while following the code through video. Everything was going great but now i'm stuck trying to save the goat door/host choice. I attached a screen shot and will add my code here as well, thank you again for helping me.
host_choice <- doors[-my.initial.pick]
host_choice == "goat"
which(host_choice == "goat")
select_host_choice <- function(doors, my.initial.pick) {
#update our options by taking out contestant's initial pick
host_choice <- sample(which(host_choice == "goat"), size = 98, replace = F)
host_choice <- c(host_choice)
return(host_choice)
}
``
host_choice <- select_host_choice(doors, my.initial.pick)
host_choice
Error in sample.int(x, size, replace, prob) :
cannot take a sample larger than the population when 'replace = FALSE'
<img width="713" alt="Screen Shot 2024-08-27 at 6 20 30 PM" src="https://github.com/user-attachments/assets/c3f7e648-836d-4a96-b8af-c6848a7e0ac9">
Hello @lindaalvarez,
Glad to see you're making progress! You'll want to note your error message:
Error in sample.int(x, size, replace, prob) : cannot take a sample larger than the population when 'replace = FALSE'
This is because you have a sample size set for 98 (from the example) and you should only have 2 objects to select from. You'll want to update this to only select 1.
I figured it out! Thank you so much for your help!
Hello, @castower I'm running into issues in my step four of Module One. I'm watching the video on module one and referring to the 100 envelopes lab. I think i'm getting confused comparing Step Four and the Host Selects 98 envelopes and Store Host's Choice. I back tracked on some on my code but here it is:
######## PSUEDOCODE
INSERT LOGIC HERE
#######
STEP 4:
####### PSUEDOCODE
#######