Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Chisquared Monte Carlo integration

Options
  • 07-11-2010 2:51am
    #1
    Registered Users Posts: 37


    Hi, I have trouble to use this Monte Carlo integration method.

    The question is " compute sample means for chi-squared distribution with degrees of freedom df=5. Using sample size of 10,50,100,500,1000,5000,10000"

    I known rchisq(10,df=5) is the command to generate a random sample size 10 from a chisquare distribution with df=5.

    Here is the command my lecture gave:
    Step 1: Generate a large sample from relevant distribution
    e.g. unifrv100_runif(n=100, min=0, max=1)

    Step 2: Compute sample moment
    muMC_ mean(unifrv100) [0.528, mu is ]
    varMC_var(unifrv100) [0.084, var^2 is 0.083]

    when I try to type it into R, I got "Error: could not find function "unifrv100_runif"

    I don't really understand those command my lecture gave, is anyone could explain, or give me a hint. Thank you!!!


Comments

  • Registered Users Posts: 12,972 ✭✭✭✭bnt


    Looks to me like something got mangled in translation: I think the underscores should be "<-" variable assignments, and the bits in square brackets are comments, not commands. So unifrv100 is not a command, it's a variable name. These commands work:
    unifrv100 <- runif(n=100, min=0, max=1)
    muMC <- mean(unifrv100)
    varMC <- var(unifrv100)
    
    Note that these return nothing on screen: if you want to see the results, you have to just enter the variable name e.g.
    > muMC
    [1] 0.4947008
    > varMC
    [1] 0.08191964
    
    (Your results will vary.)

    From out there on the moon, international politics look so petty. You want to grab a politician by the scruff of the neck and drag him a quarter of a million miles out and say, ‘Look at that, you son of a bitch’.

    — Edgar Mitchell, Apollo 14 Astronaut



Advertisement