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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Chisquared Monte Carlo integration

  • 07-11-2010 1: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,076 ✭✭✭✭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