Stats Problem

Discussion in 'Community Discussion' started by macbaseball, Nov 19, 2006.

  1. macbaseball macrumors 6502a

    macbaseball

    Joined:
    Feb 27, 2005
    Location:
    Northern California
    #1
    I have this Stats problem due tomorrow and I can get my application for my TI-84 to work. Could someone help me out.

    Here is the problem:

    Suppose there are eight hermits on an island, and that one of the hermits becomes infected with a certain strain of virus. The infected hermit is contagious for a 24-hour period and not thereafter, and once a hermit has this particular infection, the hermit is immune thereafter. Further suppose that the
    infected hermit randomly selects one of the other hermits to visit on the day he is contagious, and that the second hermit to become infected repeats the process. If the visited hermit has already had the infection and is immune, the epidemic dies out.

    I have to come up with a Program on the calculator. This is what I have so far:

    0?B
    randInt(1,8)?A
    B+1?B
    randInt(1,8,1)?C
    If A?C:Then B+1?B
    If A=C Then Repeat
    randInt(1,8,1)?D
    If A?D and C?D Then B+1?B
    If A=D or C=D Then disp B
    randInt(1,8,1)?E
    If A?E and C?E and D?E Then B+1?B
    If A=E or C=E or D=E Then disp B
    randInt(1,8,1)?F
    If A?F and C?F and D?F and E?F Then B+1?B
    If A=F or C=F or D=F or E=F Then disp B
    randInt(1,8,1)?G
    If A?G and C?G and D?G and E?G and F?G Then B+1?B
    If A=G or C=G or D=G or E=G and F=G Then disp B
    randInt(1,8,1)?H
    If A?H and C?H and D?H and E?H and F?H and G?H Then B+1?B
    If A=H and C=H and D=H and E=H and F=H and G=H Then disp B
    randInt(1,8,1)?I
    If A?I and C?I and D?I and E?I and F?I and G?I Then B+1?B
    If A=I and C=I and D=I and E=I and F=I and G=I Then disp B

    Could anyone look at this model or advise me on how to make a quick program to simulate this. Thanks.

    Edit: The question mark represents the STO key. It didn't paste in correctly.
     
  2. swiftaw macrumors 603

    swiftaw

    Joined:
    Jan 31, 2005
    Location:
    Omaha, NE, USA
    #2
    The cycle ends unless the contagious person visits an uninfected person on that particular day, else the epidemic ends. Also, the number of uninfected people decreases over time.

    So something like this, I know this isn't the correct syntax, but hopefully you get the idea.

    Let X = 1 (X will store the number of infected people, at the beginning, that is 1)
    Z=0 (indicator variable to determine when to stop repeat loop)
    REPEAT
    Let Y = random number between 0 and 1 (random number generator to determine who the contagious person meets)
    IF Y >= (X-1)/7 then X = X + 1 (contagious person met uninfected person, add 1 to total number of infected people)
    ELSE Z = 1
    UNTIL Z = 1 or X = 8

    Print X
     
  3. macbaseball thread starter macrumors 6502a

    macbaseball

    Joined:
    Feb 27, 2005
    Location:
    Northern California
    #3
    The TI can only chose random integers. Assume that you randomly select an integer between 1 and 8. I can substitute that in for the top Y, but I'm not sure if the rest of the formula works. I don't think so, but could you respond. Thanks a lot for your help.
     
  4. swiftaw macrumors 603

    swiftaw

    Joined:
    Jan 31, 2005
    Location:
    Omaha, NE, USA
    #4
    Let X = 1 (X will store the number of infected people, at the beginning, that is 1)
    Z=0 (indicator variable to determine when to stop repeat loop)
    REPEAT
    Let Y = random number between 1 and 7 (random number generator to determine who the contagious person meets)
    IF Y >= X then X = X + 1 (contagious person met uninfected person, with probability X/7, add 1 to total number of infected people)
    ELSE Z = 1
    UNTIL Z = 1 or X = 8


    Let me know if you need me to explain any of the above
     
  5. macbaseball thread starter macrumors 6502a

    macbaseball

    Joined:
    Feb 27, 2005
    Location:
    Northern California
    #5
    I don't understand why Y >= X determines whether the hermit has been selected before or not. What if the original Hermit infects Hermit #3. Then Hermit #3 infects Hermit #1. Wouldn't that stop the loop, without a immune hermit being selected.
     
  6. CanadaRAM macrumors G5

    CanadaRAM

    Joined:
    Oct 11, 2004
    Location:
    On the Left Coast - Victoria BC Canada
    #6
    Well, who gets to decide what order they are numbered in? You do, of course.
     
  7. swiftaw macrumors 603

    swiftaw

    Joined:
    Jan 31, 2005
    Location:
    Omaha, NE, USA
    #7
    I'm not keeping of track of which hermits have been infected and which have not, only how many have been infected.

    I guess it depends what you need, do you need to track exactly which individuals are infected or just how many end up getting infected.

    If you only need to keep track of how many end up getting infected then my code will work. Think about it, on any given day (at most) one person is contagious. They visit one person, if X of the 8 people are currently infected then there is a probability of (8 - X) / 7 that the contagious person will visit an uninfected person. This probability simulation is done in my code.


    However, if you want to keep track of each person individual you'll need a little more complicated code.
     
  8. macbaseball thread starter macrumors 6502a

    macbaseball

    Joined:
    Feb 27, 2005
    Location:
    Northern California
    #8
    Sorry, I should have put that into the original problem. The teacher put an example of the simulation below the written problem, which numbers the hermits 1-8. He just used a random number table, whereas I'm supposed to program it.

    Edit: It actually makes sense because if the infected hermit vists a immune hermit, there is no way he can spread it...
     
  9. swiftaw macrumors 603

    swiftaw

    Joined:
    Jan 31, 2005
    Location:
    Omaha, NE, USA
    #9
    So you need to know which individual hermits get infected and which dont, ok, so.

    Create a list called X, which has 8 elements, either 0 or 1. so if we assume that at the start hermit 1 is infected then the initial list should look like this

    {1 0 0 0 0 0 0 0}->X
    0->Z
    Now,

    REPEAT
    Y = random number between 1 and 8 representing who contagious person meets that day
    IF Y <> X (person cannot meet themselves) THEN
    IF X(Y) = 0 (person is uninfected) then X(Y) = 1 (person is now infected)
    ELSE Z = 1 (disease has stopped spreading)
    END IF
    UNTIL Z = 1

    Print X


    I think that works
     
  10. macbaseball thread starter macrumors 6502a

    macbaseball

    Joined:
    Feb 27, 2005
    Location:
    Northern California
    #10
    In theory it should work, and it makes sense, but I can't get the TI syntax to let me do it. It won't allow me to assign a variable to the number to the corresponding slot in list X.
     
  11. swiftaw macrumors 603

    swiftaw

    Joined:
    Jan 31, 2005
    Location:
    Omaha, NE, USA
    #11
    It objects to the X(Y) part?
     
  12. macbaseball thread starter macrumors 6502a

    macbaseball

    Joined:
    Feb 27, 2005
    Location:
    Northern California
    #12
    Yep. The lists are very temperamental - it's difficult to program them.

    Also I'm not closing the Repeat command. (I think, I have never programmed a TI before, which is part of the problem.)
     
  13. swiftaw macrumors 603

    swiftaw

    Joined:
    Jan 31, 2005
    Location:
    Omaha, NE, USA
    #13
    {1 0 0 0 0 0 0 0}->X
    0->Z


    Now,

    REPEAT
    Y = random number between 1 and 8 representing who contagious person meets that day
    IF Y <> X (person cannot meet themselves) THEN
    IF Y = 1
    IF X(1) = 0 THEN X(1)->1 ELSE Z = 1
    END IF
    IF Y = 2
    IF X(2) = 0 THEN X(2)->1 ELSE Z = 1
    END IF
    ...
    END IF
    UNTIL Z = 1

    Print X
     
  14. macbaseball thread starter macrumors 6502a

    macbaseball

    Joined:
    Feb 27, 2005
    Location:
    Northern California
    #14
    I'm using L1 (List 1) for X. The TI command for a slot on the list is L1(#). For example L1(3) would give you the third number in L1. I'm trying to put a variable in for the number, and it won't let you do that. So I'm trying to figure a way around that.
     
  15. swiftaw macrumors 603

    swiftaw

    Joined:
    Jan 31, 2005
    Location:
    Omaha, NE, USA
    #15
    Check my previous post, I eliminated the need to put a variable in the parenthesis, instead i wrote each case separately
     
  16. macbaseball thread starter macrumors 6502a

    macbaseball

    Joined:
    Feb 27, 2005
    Location:
    Northern California
    #16
    Should I repeat for X(3), X(4), etc.
     
  17. swiftaw macrumors 603

    swiftaw

    Joined:
    Jan 31, 2005
    Location:
    Omaha, NE, USA
    #17
    Yes
     
  18. macbaseball thread starter macrumors 6502a

    macbaseball

    Joined:
    Feb 27, 2005
    Location:
    Northern California
    #18
    Getting closer. This is what I have right now. It doesn't like where the Repeat tag is. Also, I'm not sure about the End tag. (It just stops at repeat so I'm not sure if it will take it or not) Could you take a look...

    ClrHome
    ClrList L1
    {0,0,0,0,0,0,0,0}?L1

    Repeat
    X=(randInt(1,8)
    If X=1
    If L1(1)≠1ThenL1(1)(Store)1
    If L1(1)=1Thensum(L1)(Store)G
    If X=2
    If L1(2)≠1ThenL1(2)(Store)1
    If L1(2)=1Thensum(L1)(Store)G
    If X=3
    If L1(3)≠1ThenL1(3)(Store)1
    If L1(3)=1Thensum(L1)(Store)G
    If X=4
    If L1(4)≠1ThenL1(1)(Store)1
    If L1(4)=1Thensum(L1)(Store)G
    If X=5
    If L1(5)≠1ThenL1(5)(Store)1
    If L1(5)=1Thensum(L1)(Store)G
    If X=6
    If L1(6)≠1ThenL1(1)(Store)6
    If L1(6)=1Thensum(L1)(Store)G
    If X=7
    If L1(7)≠1ThenL?(7)(Store)1
    If L1(7)=1Thensum(L1)(Store)G
    If X=8
    If L1(8)≠1ThenL1(8)(Store)1
    If L1(8)=1Thensum(L1)(Store)G
    End
    Disp G
     
  19. swiftaw macrumors 603

    swiftaw

    Joined:
    Jan 31, 2005
    Location:
    Omaha, NE, USA
    #19

    I'm not sure on the syntax of the TI-83, also not sure what all the ? represent
     
  20. macbaseball thread starter macrumors 6502a

    macbaseball

    Joined:
    Feb 27, 2005
    Location:
    Northern California
    #20
    I'll try to fill in as many as ? as I can. Do you even have a guess on the Repeat Tag? I believe the TI just uses Basic...
     
  21. swiftaw macrumors 603

    swiftaw

    Joined:
    Jan 31, 2005
    Location:
    Omaha, NE, USA
    #21
    Yes, you need to put the condition next to the REPEAT, so for example

    REPEAT Z=1
    all the commands
    END

    Will repeat all the commands between REPEAT and END until Z=1 is true
     
  22. macbaseball thread starter macrumors 6502a

    macbaseball

    Joined:
    Feb 27, 2005
    Location:
    Northern California
    #22
    Now it doesn't come back with an error - the loop just never finishes.

    Here's the current version:

    ClrHome
    ClrList L?
    {0,0,0,0,0,0,0,0}?L?

    Repeat Z=1
    X=(randInt(1,8)
    If X=1
    If L?(1)=0ThenL?(1)?1 Else Z=1
    If X=2
    If L?(2)=0ThenL?(2)?1 Else Z=1
    If X=3
    If L?(3)=0ThenL?(3)?1 Else Z=1
    If X=4
    If L?(4)=0ThenL?(4)?1 Else Z=1
    If X=5
    If L?(5)=0ThenL?(5)?1 Else Z=1
    If X=6
    If L?(6)=0ThenL?(1)?1 Else Z=1
    If X=7
    If L?(7)=0ThenL?(7)?1 Else Z=1
    If X=8
    If L?(8)=0ThenL?(8)?1 Else Z=1
    End
    G=sum(L?)
    Disp G

    Edit: I looked in L1 and the numbers are not changing from 0 to 1.
     
  23. macbaseball thread starter macrumors 6502a

    macbaseball

    Joined:
    Feb 27, 2005
    Location:
    Northern California
    #23
    That it good enough. Thanks for all of your help...
     
  24. swiftaw macrumors 603

    swiftaw

    Joined:
    Jan 31, 2005
    Location:
    Omaha, NE, USA
    #24
    You probably need something like

    If L1(1)=0 then 1->L1(1) else 1->Z

    maybe that is the syntax you need
     
  25. macbaseball thread starter macrumors 6502a

    macbaseball

    Joined:
    Feb 27, 2005
    Location:
    Northern California
    #25
    You were right about the syntax, but it still doesn't work. I think it might have to do with the double if statement.

    If X=1
    If L1(1)=0 then 1(Store)L1(1) Else Z=1

    Do I need to complete the first If statement
     

Share This Page