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

                    Thal And Out Agency railway station See also References External links Navigation menuOfficial Web Site of Pakistan RailwaysArchivedOfficial Web Site of Pakistan Railwayseeexpanding ite

                    Understanding generators in Python2019 Community Moderator ElectionGenerator function not working pythonFor loop not executing two timesGenerators - Printing generated valuesWhy can a python generator only be used once?What exactly do generators do?What does the “yield” keyword do?What does “list comprehension” mean? How does it work and how can I use it?sklearn Kfold acces single fold instead of for loopIs a generator the callable? Which is the generator?Apply Border To Range Of Cells Using OpenpyxlCalling an external command in PythonWhat are metaclasses in Python?What is the difference between @staticmethod and @classmethod?Finding the index of an item given a list containing it in PythonDifference between append vs. extend list methods in PythonHow can I safely create a nested directory in Python?Does Python have a ternary conditional operator?Understanding slice notationUnderstanding Python super() with __init__() methodsDoes Python have a string 'contains' substring method?

                    How can I change the color of pagination dots of UIPageControl?How to change UIPageControl dotsIs there a way to change page indicator dots colorCustomize dot with image of UIPageControl at index 0 of UIPageControlNo visible @interface for 'NSObject<PageControlDelegate>' declares the selector 'pageControlPageDidChange:'How to change the color of pagination dots in UIPageControl with a different color per pagepagecontrol indicator custom image instead of DefaultChanging the colour of UIPageControl dots in MonoTouchpagecontrol selectable page visibility color?Alternative way to load ViewControllers on a UIPageControlHow to set only layer.border-color for UIpage control dots in swiftHow can I develop for iPhone using a Windows development machine?How to change the name of an iOS app?UITableView - change section header coloruipagecontrol indicator(dot)issueCustom UIPageControl dots color not changingchange the interspace between UIPageControl dotsHow to change Status Bar text color in iOSHow can I change image tintColor in iOS and WatchKitUIPageControl dots with larger space in between each dotsHow to change the color of pagination dots in UIPageControl with a different color per page