Search

  • Two envelopes problem

    @Michael

    Simulation in R to demonstrate the different sampling mechanisms.

    cases=matrix(c(c(10,5),c(10,20)),nrow=2,ncol=2,byrow=FALSE)
    
    number_of_envelope_pairs=10000
    resulting_envelope_value_C=rep(0,number_of_envelope_pairs)
    #Case_C
    for(i in 1:number_of_envelope_pairs){
      my_envelope_pair=cases[,rbinom(1,1,0.5)+1]
      after_switch=my_envelope_pair[2] #this chooses "the other one than 10"
      resulting_envelope_value_C[i]=after_switch
    }
    case_C_gain=mean(resulting_envelope_value_C-10)
    case_C_gain #can see it's 2.5
    

    Onto something that sounds like Case_A, and something you can to do it to make it superficially resemble Case_C.

    #Something that sounds like Case_A
    my_envelopes=rep(0,number_of_envelope_pairs)
    my_envelopes_switch_gain=my_envelopes
    for(i in 1:number_of_envelope_pairs){
      case_index=rbinom(1,1,0.5)+1
      envelope_index=rbinom(1,1,0.5)+1
      my_envelopes[i]=cases[envelope_index, case_index]
      my_envelopes_switch_gain[i]=cases[-envelope_index, case_index]-my_envelopes[i]
      }
    mean(my_envelopes_switch_gain) #approx 0, this is if you don't open the envelope
    
    #illustrating the conditioning, NB this is not the same as conditioning on
    #the pair being (5,10) or the pair being (10,20)
    #this is the gain given the chosen envelope is 10 and the
    #other envelope is known to be 5 or 20.
    mean(my_envelopes_switch_gain[my_envelopes==10])
    #this gives you approx 2.5 as we saw in case C.
    

    You notice that when you condition on "having your envelope be 10" in that set up, you're subsetting to cases where the gain is -5 or 10, and those occur with equal probability since the cases (5,10) and (10,20) occur with equal probability. If you were to condition on your envelope being 10 in the loop (case index=1), you end up with exactly the same gain numerically but it represents a subjectively different belief state for an agent. Why? The subsetting done at the end lets you look at the whole ensemble of cases where the first envelope was 10, where the assignment of 10 was random. Fixing the envelope as 10 within case makes the assignment of 10 nonrandom.

    #Thing which is actually Case_A
    my_envelopes=rep(0,number_of_envelope_pairs)
    my_envelopes_switch_gain=my_envelopes
    for(i in 1:number_of_envelope_pairs){
      what_case_am_i_in_given_i_have_10=rbinom(1,1,0.5)+1
    #random assignment of case, 10 provides no knowledge of case
      five_ten_switch_gain_given_random_envelope=0
    #conditioning on pair being 5,10, gain is known
      ten_twenty_switch_gain_given_random_envelope=0
    #conditioning on pair being 10,20, gain is known
      case_gains=c(five_ten_switch_gain_given_random_envelope,
                   ten_twenty_switch_gain_given_random_envelope)
      my_envelopes_switch_gain[i]=case_gains[what_case_am_i_in_given_i_have_10]
    }
    
    mean(my_envelopes_switch_gain)#this is just 0
    

    The thing we're butting heads on, in my view, is the Case_A inner loop line 1, which is where the randomness comes in through the allocation of pairs. If at any point, in the loop, the agent *knows* what case they're in, their gain is deterministic. When you grant that knowledge hypothetically, you either enter subcase A 1 (the first gain line) or subcase A 2 (the second gain line). Once you've done those hypothetical calculations, you reintroduce the randomness of allocating envelopes in the next line to choose the received gain.
  • Mathematical Conundrum or Not? Number Six

    Something else I would like to point out, is that assuming that the probability of any given x must come from a discrete distribution is not necessarily true. In fact I used a selection method where the actual chance mechanism was applied to a continuous distribution in this very thread.


    two.envelopes <- function(){
    x <- (runif(1))
    x <- (abs(as.numeric(format(round(x, 3)))))*10 
    #randomly selects a number 
    #limits the number of decimal places x can have and muiltples x by 10 to simluate realistic dollar values.
    p <- c(x,2*x)
    A <- sample(p, 1, replace=F)
    #creates a vector with x and 2x then randomly selects one for A.
    if (A == x) {
    B <- 2*x
    } else {
    (B <- x)
    }
    return(c(A,B))
    }
    

    I used a continuous uniform distribution to randomly selected an x then formatted it into real dollar values. Now who is to say that such a chance mechanism was not used to fill the envelopes?

    If a probabilistic approach is to reason from a known population then the known population is x or 2x. Where x came from and how it was chosen is something we don't know.
  • Mathematical Conundrum or Not? Number Six

    I changed the code a bit to come up with another visual demonstration. I changed the two.envelopes function to just output A and then copied it to another function called two.envelopes.s which outputs B.

    What this simulates is if you never switch then you walking away with A and if you always switch then you walk away with B. I used a normal distribution for this example but honestly you can do the same thing for any distribution since the content of A and B are determined by the same chance event.

    The point of this demonstration is to show that the possible distribution of A is the same as the possible distribution of B so I have included some graphs that can be visually compared, and I use a Kolmogorov-Smirnov Tests, also known as the K-S test. This is a non-parametric test, and if you want the details on how it works just Google it, the concept is actually really simple.

    The K-S test compares two distributions to see if they match.

    The hypotheses works like this: Let F(x) and S(x) designate some unknown distribution functions of the X's and Y's respectively.

    Then our following two-sided null hypothesis is: F(x) = S(x) for all of x
    Then our alternative hypothesis is: F(x) does not equal S(x) for at least one value of x

    If you have never seen a classical statistical hypotheses test, the short and sweet of it, is if we get a low p-value we consider this evidence against the null hypothesis. The lower the p-value the greater the evidence. P-values range from 0 to 1. They are the probability of a ratio as extreme or more extreme than the observed given the null is true. Note they are not evidence for the null, failing to reject does not prove a null. The null is just that annoying guy that always demands you prove everything you say, but it is the alternative hypothesis that we are really testing for.


    Here is the code:

    two.envelopes <- function(){
    x <- (rnorm(1))
    x <- (abs(as.numeric(format(round(x, 3)))))*10 
    #randomly selects a number 
    #limits the number of decimal places x can have and muiltples x by 10 to simluate realistic dollar values. 
    p <- c(x,2*x)
    A <- sample(p, 1, replace=F)
    #creates a vector with x and 2x then randomly selects one for A.
    if (A == x) {
    B <- 2*x
    } else {
    (B <- x)
    }
    return(c(A))
    }
    #sets the value for B based on: if A = x then B = 2x or if A = 2x then B = x
    g <- replicate(10000, two.envelopes())
    
    
    two.envelopes.s <- function(){
    x <- (rnorm(1))
    x <- (abs(as.numeric(format(round(x, 3)))))*10 
    #randomly selects a number 
    #limits the number of decimal places x can have and muiltples x by 10 to simluate realistic dollar values. 
    p <- c(x,2*x)
    A <- sample(p, 1, replace=F)
    #creates a vector with x and 2x then randomly selects one for A.
    if (A == x) {
    B <- 2*x
    } else {
    (B <- x)
    }
    return(c(B))
    }
    #sets the value for B based on: if A = x then B = 2x or if A = 2x then B = x
    g.s <- replicate(10000, two.envelopes())
    
    library(ggplot2)
    plot(g)
    plot(g.s)
    ggplot() + aes(g)+ geom_histogram(binwidth=10, colour="black", fill="white")
    
    ggplot() + aes(g.s)+ geom_histogram(binwidth=10, colour="black", fill="white")
    
    ks.test(g, g.s)
    
    #K-S test results
    
    p-value will be approximate in the presence of ties
    	Two-sample Kolmogorov-Smirnov test
    
    data:  g and g.s
    D = 0.0077, p-value = 0.9283
    alternative hypothesis: two-sided
    
    

    So we see with a D test statistics of 0.0077 and a 0.92 p-value we don't have strong enough evidence to support the alternative hypothesis that the two distributions are reasonably different.

    Of course this was an expected outcome and would remain true no matter how X was selected, as once X is selected its distribution in the envelopes is now something separate which depends on how the envelopes themselves are selected.

    If you don't like the K-S test here are some plots that allow you to view the similarities:

    There are scatter plots of each distribution and histograms of each. They will look very similar.

    Scatter Plots:

    https://ibb.co/ksr0P8

    https://ibb.co/bW6gxT

    Histograms:

    https://ibb.co/c9w3Bo

    https://ibb.co/h30248
  • Mathematical Conundrum or Not? Number Six

    I have been messing with this in R, and wrote a function which simulates the game. Note that is not a simple repeated sample from a predefined sample space. It simulates the game, by selecting X randomly then randomly places X or 2X into A. Then X or 2X into B based on what is in A. It then returns the value of both A and B.

    The function, which is called two.envelopes, is one go at the game, and then the function replicate can be used to run it several times in a row. Which I did then output those to a matrix.

    I ran the game simulation under 4 different conditions: Where X is chosen from a normal distribution, where X is chosen from a uniform distribution, where is X is chosen from a Cauchy distribution and where X is sampled from an interval scale. The function could be used as well to do actual statistical analyses either Classical or Bayesian, by generating enough simulated data to support such an approach.

    I know these efforts will be lost on some people, but it does provide a visual summary which demonstrates the distribution in which X was selected from is not significant when assessing the possible outcome of envelope A and B concerning X or 2X.

    Also, this gives results that can be reviewed which are not dependent on defining a sample space or on calculating an expected value.

    Normal Distribution:

    two.envelopes <- function(){
    x <- (rnorm(1))
    x <- (abs(as.numeric(format(round(x, 3)))))*10 
    #randomly selects a number 
    #limits the number of decimal places x can have and muiltples x by 10 to simluate realistic dollar values. 
    p <- c(x,2*x)
    A <- sample(p, 1, replace=F)
    #creates a vector with x and 2x then randomly selects one for A.
    if (A == x) {
    B <- 2*x
    } else {
    (B <- x)
    }
    return(c(A,B))
    }
    #sets the value for B based on: if A = x then B = 2x or if A = 2x then B = x
    g <- t(replicate(100, two.envelopes()))
    head(g)
    
    #results
    
          [,1]  [,2]
    [1,]  5.23 10.46
    [2,]  5.48 10.96
    [3,] 25.60 12.80
    [4,]  6.17 12.34
    [5,]  3.88  7.76
    [6,]  7.59 15.18
    



    Uniform distribution:

    two.envelopes <- function(){
    x <- (runif(1))
    x <- (abs(as.numeric(format(round(x, 3)))))*10 
    #randomly selects a number 
    #limits the number of decimal places x can have and muiltples x by 10 to simluate realistic dollar values.
    p <- c(x,2*x)
    A <- sample(p, 1, replace=F)
    #creates a vector with x and 2x then randomly selects one for A.
    if (A == x) {
    B <- 2*x
    } else {
    (B <- x)
    }
    return(c(A,B))
    }
    #sets the value for B based on: if A = x then B = 2x or if A = 2x then B = x
    g <- t(replicate(100, two.envelopes()))
    head(g)
    
    #results
    
          [,1]  [,2]
    [1,] 27.20 13.60
    [2,] 28.72 14.36
    [3,] 12.49 24.98
    [4,] 12.95 25.90
    [5,] 61.18 30.59
    [6,]  2.66  1.33
    
    

    Cauchy distribution:

    two.envelopes<- function(){
    x <- (rcauchy(1, location = 0, scale = 1))
    x <- (abs(as.numeric(format(round(x, 3)))))*10 
    #randomly selects a number 
    #limits the number of decimal places x can have and muiltples x by 10 to simluate realistic dollar values. 
    p <- c(x,2*x)
    A <- sample(p, 1, replace=F)
    #creates a vector with x and 2x then randomly selects one for A.
    if (A == x) {
    B <- 2*x
    } else {
    (B <- x)
    }
    return(c(A,B))
    }
    #sets the value for B based on: if A = x then B = 2x or if A = 2x then B = x
    g <- t(replicate(100, two.envelopes()))
    head(g)
    
         [,1]  [,2]
    [1,] 10.22 20.44
    [2,] 24.54 12.27
    [3,]  2.05  4.10
    [4,]  8.96  4.48
    [5,] 15.44  7.72
    [6,] 13.74 27.48
    
    

    Interval Scale:

    two.envelopes <- function(){
    x <- (sample(1:100, 1))
    #randomly selects a number 
    p <- c(x,2*x)
    A <- sample(p, 1, replace=F)
    #creates a vector with x and 2x then randomly selects one for A.
    if (A == x) {
    B <- 2*x
    } else {
    (B <- x)
    }
    return(c(A,B))
    }
    #sets the value for B based on: if A = x then B = 2x or if A = 2x then B = x
    g <- t(replicate(100, two.envelopes()))
    head(g)
    
    #results
    
         [,1] [,2]
    [1,]   27   54
    [2,]  136   68
    [3,]   33   66
    [4,]   14   28
    [5,]   30   60
    [6,]   57  114
    

    The thing to notice here is that in all cases the absolute value of the difference between column one and column two is always equal to the lesser of the two (save rounding errors). The lesser of the two is X.

Welcome to The Philosophy Forum!

Get involved in philosophical discussions about knowledge, truth, language, consciousness, science, politics, religion, logic and mathematics, art, history, and lots more. No ads, no clutter, and very little agreement — just fascinating conversations.