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.
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.
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~