Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Chisquared Monte Carlo integration

  • 07-11-2010 02:51AM
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 Posts: 13,183 ✭✭✭✭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.)

    You are the type of what the age is searching for, and what it is afraid it has found. I am so glad that you have never done anything, never carved a statue, or painted a picture, or produced anything outside of yourself! Life has been your art. You have set yourself to music. Your days are your sonnets.

    ―Oscar Wilde predicting Social Media, in The Picture of Dorian Gray



Advertisement