How to use the 4 different norm() functions in R

แชร์
ฝัง
  • เผยแพร่เมื่อ 23 ก.ค. 2024
  • In this video I show you how to use the 4 different norm()-functions in R.
    * rnorm() can be used to draw random numbers from a normal distribution.
    * dnorm() helps you to understand the probability density function of that distribution
    * pnorm() gives you the cumulative probability of a value from that distribution
    * qnorm() tells you what value you need to be in a certain quantile of that distribution
    ⏱ Time Stamps ⌚
    0:00 - Intro and overview
    0:29 - IQ example
    1:22 - rnorm()
    2:44 - properties of the normal distribution
    4:24 - dnorm()
    5:38 - pnorm()
    7:46 - qnorm()
    9:18 - ggplot() visulizations

ความคิดเห็น • 17

  • @qwerty3465
    @qwerty3465 2 ปีที่แล้ว +4

    Usefull stuff! The new style of more live console work alongside some preprepared chunks works out well!

    • @TheDataDigest
      @TheDataDigest  2 ปีที่แล้ว +1

      Thank you for the feedback.

  • @pierre-alexandrequittet6461
    @pierre-alexandrequittet6461 2 ปีที่แล้ว +6

    Just discovered your videos, they're so GREAT thank you for sharing !

    • @TheDataDigest
      @TheDataDigest  2 ปีที่แล้ว +1

      Thanks for leaving such a nice comment. I will try to upload many more, so that your discovery was really worth it :)

  • @viniemeralda3395
    @viniemeralda3395 9 หลายเดือนก่อน +1

    Thank you very much! This is very helpful

  • @urbisurbis
    @urbisurbis ปีที่แล้ว +1

    Thanks a lot for a very useful content! As a beginner in R, I wonder is there any way how to generate random integers (whole numbers like 1, 2, 3, 4 ) instead of fractions (like 1.2375, 2.3158, 3.1425 etc.) from a normal distribution? When the mean and SD is predetermined. rnorm(N, mean, SD) is very useful, but can't figure out yet how to get integers only.

    • @hassanhijazi4757
      @hassanhijazi4757 ปีที่แล้ว +1

      you can use `sample()` function.

    • @TheDataDigest
      @TheDataDigest  ปีที่แล้ว

      Great question. Glad you asked. There are many options to accomplish that. You can wrap the ceiling() or floor() function around rnorm(). This will round up or down to integers.
      You can also use round(rnorm(...), digits = 0) to round either up or down depending on the decimal.
      Try: round(rnorm(n = 10, mean = 178, sd = 12), digits = 0)
      This will give you 10 simulated rounded integer from the male height distribution.
      I will also comment to the suggestion from Hassan below so keep an eye out for that.

    • @TheDataDigest
      @TheDataDigest  ปีที่แล้ว

      @@hassanhijazi4757 That is a very interesting suggestion because in sample you can specify the probability of each integer being drawn.
      As in: sample(1:10, size = 50, replace = TRUE, prob = dnorm(sort(rnorm(10))))
      This will sample 50 numbers from the sequence of 1 to 10, with replacement of course. But the drawing will follow a normal distribution, i.e. the probability density of it. That is why I use dnorm() on top of sorted rnorm()
      Now the numbers 5 and 6 are more likely to be drawn.
      You will see that if you use table() or hist() on the results.

  • @korman9872
    @korman9872 ปีที่แล้ว +2

    tx sir

  • @FiddiDinoTobi
    @FiddiDinoTobi 7 หลายเดือนก่อน +1

    So let's assume that stocks are normally distributed. Is the pnorm for finding what the probability of me either earning or losing on a stock is? Like say what is the possiblity of earning 5 million on a given stock. and qnorm is for example, what is probability that I will get a return of 10% on a given stock?

    • @TheDataDigest
      @TheDataDigest  7 หลายเดือนก่อน +1

      Hi, thanks for your 2 questions. Let me answer them but then give you extra warning at the end :).
      (1) Kindof yes, if returns (win or loss) of stocks are normally distributed with a mean=0 then pnorm() will give you the probability of a certain return being achieved.
      For example: I assume a mean growth of 5% over a year with a standard deviation of 15% (stocks can be quite variable over a year). pnorm(q = 1.05, mean = 1.05, sd = 0.15) will give you 0.5. Which means that there is a 50% chance a stock will grow to 1.05 (q-value), or less. pnorm is the cummulative probability. So you always have to state the probability of a range. What is the chance of having at least 5% growth (it can be lower). It is better to ask for a specific range. Like getting a growth of 5-10%:
      pnorm(q = 1.10, mean = 1.05, sd = 0.15) - pnorm(q = 1.05, mean = 1.05, sd = 0.15) which will be 0.1305.
      With qnorm() you can ask what growth the top 20% of stocks will have:
      qnorm(p = 0.8, mean = 1.05, sd = 0.15) gives 1.176, which means that given the distribution the top 20% of stocks will have a return of 17.6% or higher.
      The question regarding the 5 million depends on how much you invest originally.
      And the warning I want to give is that you have to really check whether the return is normally distributed. If a stock increases 3 times it is +200% but if it decreases to one third of its values it is -67%. So the distribution might be skewed and maybe you need to mathematically transform it before using pnorm() and qnorm(). Hope that helped.

  • @WahranRai
    @WahranRai ปีที่แล้ว +2

    Reduce the speed !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

    • @floriansitte-kratzsch7355
      @floriansitte-kratzsch7355 ปีที่แล้ว +1

      Settings >>> Playback speed >>> 0.75.
      I personally like 1.5 for this channel :)

    • @desertezz
      @desertezz ปีที่แล้ว

      @@floriansitte-kratzsch7355 aren't you fancy :)

    • @yahianad
      @yahianad 2 หลายเดือนก่อน

      You're totally right