Probability of more than one person

Hello,

I am quite new to R Studio and I understand that pnorm can do a probability of a person in a situation but do I use the same for "pick 10 random people". Is that still pnorm or another function? I have currently just done it with equations but I'm sure I am supposed to be doing it with a function.

Thanks!

Welcome to this community. pnorm is all about normal distribution function ( like elongated S curve)

pnorm(q = 10, mean = 0, sd = 1)
#> [1] 1
pnorm(q = -10, mean = 0, sd = 1)
#> [1] 7.619853e-24
pnorm(q = 0, mean = 0, sd = 1)
#> [1] 0.5
pnorm(q = c(10, -10, 0), mean = 0, sd = 1)
#> [1] 1.000000e+00 7.619853e-24 5.000000e-01

The first three's are essentially
P(-inf<= X <=10 ) = 1
P(-inf<= X <= -10 ) = 7.619853e-24 (close to 0)
P(-inf<= X <=0 ) = 0.5
Last one, we can feed an vector to get those probabilities.
Do you try to get 10 random numbers from a specific normal distribution?

I need to have 10 random people with IQs between two given numbers. I can do 1 person with a specific IQ but was unsure how to do 10 random people AND the IQ numbers.

set.seed(42) #for repeatable 'random'

#get 50 samples from a normal distribution 
# with mean 100 
# and standard deviation 30
# also round it as we dont typically see fractional IQ numbers
(iqlist <- round(rnorm(50,mean=100,sd = 30)))

#some metadata on the 50 values we got
length(iqlist)
mean(iqlist)
sd(iqlist)
# as expected...

As @nirgrahamuk indicated how to get 10 points from a specified normal distribution. This is fine, but as normal distribution has infinite range, you may get some values which are very small or big (very very rarely) which may be out of your range. If you need to draw some numbers between two number, you can try follows (one is using uniform distribution and other is is random sampling between 40 and 160). It will always be between 40 and 160.

# 
set.seed(42)
round(runif(n = 10, min = 40, max = 160))
#>  [1] 150 152  74 140 117 102 128  56 119 125
sample(x = 40:160, size = 10)
#>  [1]  86  63 110 139 128  76 149  59  65 150

I assume that you have data for many people in the form of data.frame and one of the columns is IQ. If so, you can do something like that:

library(tidyverse)

mpg %>%
  # Filter observation that match your criteria. In this example "displ" 
  # should be >= 2 and <= 5
  filter(between(displ, 2, 5)) %>%
  # Select desired number of random observations (here 3)
  sample_n(3)

#> # A tibble: 3 x 11
#>   manufacturer model    displ  year   cyl trans   drv     cty   hwy fl    class 
#>   <chr>        <chr>    <dbl> <int> <int> <chr>   <chr> <int> <int> <chr> <chr> 
#> 1 chevrolet    malibu     2.4  2008     4 auto(l~ f        22    30 r     midsi~
#> 2 hyundai      sonata     2.4  2008     4 auto(l~ f        21    30 r     midsi~
#> 3 audi         a4 quat~   2    2008     4 auto(s~ 4        19    27 p     compa~

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.