How can we find E(X^n) for a discrete random variable X in R?Random sample from given bivariate discrete distributionGrouping functions (tapply, by, aggregate) and the *apply familyDrop data frame columns by nameGenerate a random point within a circle (uniformly)How to make a great R reproducible exampleComputing SNR with discrete random variablescalculate mean and variance for weighted discrete random variables in RHow can I view the source code for a function?Discrete probability distribution with a given maximumCreate discrete random variables to find the probability that both events A and B happen

Drawing ramified coverings with tikz

Are the IPv6 address space and IPv4 address space completely disjoint?

Why did the HMS Bounty go back to a time when whales are already rare?

How do I color the graph in datavisualization?

If infinitesimal transformations commute why dont the generators of the Lorentz group commute?

Loading commands from file

How to explain what's wrong with this application of the chain rule?

Multiplicative persistence

Why did the EU agree to delay the Brexit deadline?

Open a doc from terminal, but not by its name

How much character growth crosses the line into breaking the character

Why electric field inside a cavity of a non-conducting sphere not zero?

Is the U.S. Code copyrighted by the Government?

Melting point of aspirin, contradicting sources

250 Floor Tower

Redundant comparison & "if" before assignment

How do you respond to a colleague from another team when they're wrongly expecting that you'll help them?

Does a 'pending' US visa application constitute a denial?

What is this called? Old film camera viewer?

Approximating irrational number to rational number

What is Cash Advance APR?

Energy measurement from position eigenstate

Is it improper etiquette to ask your opponent what his/her rating is before the game?

Is it possible to put a rectangle as background in the author section?



How can we find E(X^n) for a discrete random variable X in R?


Random sample from given bivariate discrete distributionGrouping functions (tapply, by, aggregate) and the *apply familyDrop data frame columns by nameGenerate a random point within a circle (uniformly)How to make a great R reproducible exampleComputing SNR with discrete random variablescalculate mean and variance for weighted discrete random variables in RHow can I view the source code for a function?Discrete probability distribution with a given maximumCreate discrete random variables to find the probability that both events A and B happen













1















Suppose values of a discrete random variable X, randomNumbers, and its distribution prob is given.



I can find E(X) using the following code:



weighted.mean(randomNumbers, prob)


How can we find E(X^n) in R?



Would this code work?



weighted.mean(randomNumbers^n, prob)









share|improve this question




























    1















    Suppose values of a discrete random variable X, randomNumbers, and its distribution prob is given.



    I can find E(X) using the following code:



    weighted.mean(randomNumbers, prob)


    How can we find E(X^n) in R?



    Would this code work?



    weighted.mean(randomNumbers^n, prob)









    share|improve this question


























      1












      1








      1








      Suppose values of a discrete random variable X, randomNumbers, and its distribution prob is given.



      I can find E(X) using the following code:



      weighted.mean(randomNumbers, prob)


      How can we find E(X^n) in R?



      Would this code work?



      weighted.mean(randomNumbers^n, prob)









      share|improve this question
















      Suppose values of a discrete random variable X, randomNumbers, and its distribution prob is given.



      I can find E(X) using the following code:



      weighted.mean(randomNumbers, prob)


      How can we find E(X^n) in R?



      Would this code work?



      weighted.mean(randomNumbers^n, prob)






      r statistics probability weighted-average






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 8 at 21:28









      divibisan

      5,03781834




      5,03781834










      asked Mar 8 at 4:44









      user366312user366312

      3,79946159319




      3,79946159319






















          1 Answer
          1






          active

          oldest

          votes


















          3














          Take Poisson random variable X ~ Poisson(2) for example.



          probabilistic method



          f1 <- function (N) 
          x <- 0:N
          p <- dpois(x, 2)
          ## approximate E[X]
          m1 <- weighted.mean(x, p)
          ## approximate E[X ^ 2]
          m2 <- weighted.mean(x ^ 2, p)
          ## approximate E[X ^ 3]
          m3 <- weighted.mean(x ^ 3, p)
          ## return
          c(m1, m2, m3)



          As N gets bigger, approximation is more and more accurate, in the sense that the sequence converges analytically.



          N <- seq(10, 200, 10)
          m123_prob <- t(sapply(N, f1))
          matplot(m123_prob, type = "l", lty = 1)


          statistical method (sampling based method)



          f2 <- function (sample_size) 
          x <- rpois(sample_size, 2)
          ## unbiased estimate of E[x]
          m1 <- mean(x)
          ## unbiased estimate of E[x ^ 2]
          m2 <- mean(x ^ 2)
          ## unbiased estimate of E[x ^ 3]
          m3 <- mean(x ^ 3)
          ## return
          c(m1, m2, m3)



          As sample_size grows, estimation is more and more accurate, in the sense that the sequence converges in probability.



          sample_size <- seq(10, 200, 10)
          m123_stat <- t(sapply(sample_size, f2))
          matplot(m123_stat, type = "l", lty = 1)





          share|improve this answer






















            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55056863%2fhow-can-we-find-exn-for-a-discrete-random-variable-x-in-r%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            3














            Take Poisson random variable X ~ Poisson(2) for example.



            probabilistic method



            f1 <- function (N) 
            x <- 0:N
            p <- dpois(x, 2)
            ## approximate E[X]
            m1 <- weighted.mean(x, p)
            ## approximate E[X ^ 2]
            m2 <- weighted.mean(x ^ 2, p)
            ## approximate E[X ^ 3]
            m3 <- weighted.mean(x ^ 3, p)
            ## return
            c(m1, m2, m3)



            As N gets bigger, approximation is more and more accurate, in the sense that the sequence converges analytically.



            N <- seq(10, 200, 10)
            m123_prob <- t(sapply(N, f1))
            matplot(m123_prob, type = "l", lty = 1)


            statistical method (sampling based method)



            f2 <- function (sample_size) 
            x <- rpois(sample_size, 2)
            ## unbiased estimate of E[x]
            m1 <- mean(x)
            ## unbiased estimate of E[x ^ 2]
            m2 <- mean(x ^ 2)
            ## unbiased estimate of E[x ^ 3]
            m3 <- mean(x ^ 3)
            ## return
            c(m1, m2, m3)



            As sample_size grows, estimation is more and more accurate, in the sense that the sequence converges in probability.



            sample_size <- seq(10, 200, 10)
            m123_stat <- t(sapply(sample_size, f2))
            matplot(m123_stat, type = "l", lty = 1)





            share|improve this answer



























              3














              Take Poisson random variable X ~ Poisson(2) for example.



              probabilistic method



              f1 <- function (N) 
              x <- 0:N
              p <- dpois(x, 2)
              ## approximate E[X]
              m1 <- weighted.mean(x, p)
              ## approximate E[X ^ 2]
              m2 <- weighted.mean(x ^ 2, p)
              ## approximate E[X ^ 3]
              m3 <- weighted.mean(x ^ 3, p)
              ## return
              c(m1, m2, m3)



              As N gets bigger, approximation is more and more accurate, in the sense that the sequence converges analytically.



              N <- seq(10, 200, 10)
              m123_prob <- t(sapply(N, f1))
              matplot(m123_prob, type = "l", lty = 1)


              statistical method (sampling based method)



              f2 <- function (sample_size) 
              x <- rpois(sample_size, 2)
              ## unbiased estimate of E[x]
              m1 <- mean(x)
              ## unbiased estimate of E[x ^ 2]
              m2 <- mean(x ^ 2)
              ## unbiased estimate of E[x ^ 3]
              m3 <- mean(x ^ 3)
              ## return
              c(m1, m2, m3)



              As sample_size grows, estimation is more and more accurate, in the sense that the sequence converges in probability.



              sample_size <- seq(10, 200, 10)
              m123_stat <- t(sapply(sample_size, f2))
              matplot(m123_stat, type = "l", lty = 1)





              share|improve this answer

























                3












                3








                3







                Take Poisson random variable X ~ Poisson(2) for example.



                probabilistic method



                f1 <- function (N) 
                x <- 0:N
                p <- dpois(x, 2)
                ## approximate E[X]
                m1 <- weighted.mean(x, p)
                ## approximate E[X ^ 2]
                m2 <- weighted.mean(x ^ 2, p)
                ## approximate E[X ^ 3]
                m3 <- weighted.mean(x ^ 3, p)
                ## return
                c(m1, m2, m3)



                As N gets bigger, approximation is more and more accurate, in the sense that the sequence converges analytically.



                N <- seq(10, 200, 10)
                m123_prob <- t(sapply(N, f1))
                matplot(m123_prob, type = "l", lty = 1)


                statistical method (sampling based method)



                f2 <- function (sample_size) 
                x <- rpois(sample_size, 2)
                ## unbiased estimate of E[x]
                m1 <- mean(x)
                ## unbiased estimate of E[x ^ 2]
                m2 <- mean(x ^ 2)
                ## unbiased estimate of E[x ^ 3]
                m3 <- mean(x ^ 3)
                ## return
                c(m1, m2, m3)



                As sample_size grows, estimation is more and more accurate, in the sense that the sequence converges in probability.



                sample_size <- seq(10, 200, 10)
                m123_stat <- t(sapply(sample_size, f2))
                matplot(m123_stat, type = "l", lty = 1)





                share|improve this answer













                Take Poisson random variable X ~ Poisson(2) for example.



                probabilistic method



                f1 <- function (N) 
                x <- 0:N
                p <- dpois(x, 2)
                ## approximate E[X]
                m1 <- weighted.mean(x, p)
                ## approximate E[X ^ 2]
                m2 <- weighted.mean(x ^ 2, p)
                ## approximate E[X ^ 3]
                m3 <- weighted.mean(x ^ 3, p)
                ## return
                c(m1, m2, m3)



                As N gets bigger, approximation is more and more accurate, in the sense that the sequence converges analytically.



                N <- seq(10, 200, 10)
                m123_prob <- t(sapply(N, f1))
                matplot(m123_prob, type = "l", lty = 1)


                statistical method (sampling based method)



                f2 <- function (sample_size) 
                x <- rpois(sample_size, 2)
                ## unbiased estimate of E[x]
                m1 <- mean(x)
                ## unbiased estimate of E[x ^ 2]
                m2 <- mean(x ^ 2)
                ## unbiased estimate of E[x ^ 3]
                m3 <- mean(x ^ 3)
                ## return
                c(m1, m2, m3)



                As sample_size grows, estimation is more and more accurate, in the sense that the sequence converges in probability.



                sample_size <- seq(10, 200, 10)
                m123_stat <- t(sapply(sample_size, f2))
                matplot(m123_stat, type = "l", lty = 1)






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 8 at 5:45









                李哲源李哲源

                48.8k1498152




                48.8k1498152





























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55056863%2fhow-can-we-find-exn-for-a-discrete-random-variable-x-in-r%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

                    2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived

                    Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme