13 R Programming (Swirl) Simulation

13 R Programming (Swirl) Simulation

memorize.aimemorize.ai (lvl 286)
Section 1

Preview this deck

Poisson distribution

Front

Star 0%
Star 0%
Star 0%
Star 0%
Star 0%

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Active users

0

All-time users

0

Favorites

0

Last updated

6 years ago

Date created

Mar 1, 2020

Cards (18)

Section 1

(18 cards)

Poisson distribution

Front

expresses the probability of a given number of events occurring in a fixed interval of time or space if these events occur with a known constant rate and independently of the time since the last event.

Back

rbinom(1, size = 100, prob = 0.7)

Front

Generate a single random variable that represents the number of heads in 100 flips of our unfair coin. A binomial random variable represents the number of 'successes' (heads) in a given number of independent 'trials' (coin flips). Note that you only specify the probability of 'success' (heads) and NOT the probability of 'failure' (tails).

Back

flips2 <- rbinom(n = 100, size = 1, prob = 0.7)

Front

if we want to see all of the 0s and 1s, we can request 100 observations, each of size 1, with success probability of 0.7, and assigning the result to a new variable called flips2.

Back

sample(1:6, 4, replace = TRUE)

Front

simulate rolling four six-sided dice

Back

rnorm(10, mean = 100, sd = 25)

Front

generate 10 random numbers from a standard normal distribution with a mean of 100 and a standard deviation of 25.

Back

rbinom()

Front

simulate random numbers from probability distributions

Back

my_pois <- replicate(100, rpois(5, 10))

Front

Use replicate(100, rpois(5, 10)) to perform this operation 100 times. Store the result in a new variable called my_pois.

Back

hist(cm)

Front

look at the distribution of our column means by plotting a histogram with hist(cm).

Back

sample(1:20, 10)

Front

sample 10 numbers between 1 and 20, WITHOUT replacement. To sample without replacement, simply leave off the 'replace' argument.

Back

rnorm(10)

Front

Generate 10 random numbers from a standard normal distribution. (The standard normal distribution has mean 0 and standard deviation 1.. So the default values for the 'mean' and 'sd' arguments to rnorm() are 0 and 1, respectively.)

Back

rpois(5, 10)

Front

Generate 5 random values from a Poisson distribution with mean 10.

Back

sample(LETTERS)

Front

To permute all 26 letters of the English alphabet. This is identical to taking a sample of size 26 from LETTERS, without replacement. When the 'size' argument to sample() is not specified, R takes a sample equal in size to the vector from which you are sampling.

Back

flips <- sample(c(0,1), 100, replace = TRUE, prob = c(0.3, 0.7))

Front

Let the value 0 represent tails and the value 1 represent heads. Use sample() to draw a sample of size 100 from the vector c(0,1), with replacement. Since the coin is unfair, we must attach specific probabilities to the values 0 (tails) and 1 (heads) with a fourth argument, prob = c(0.3, 0.7). Assign the result to a new variable called flips.

Back

rbinom()

Front

simulate a binomial random variable

Back

sum(flips)

Front

Count the actual number of 1s contained in flips.

Back

cm <- colMeans(my_pois)

Front

replicate() in previous example created a matrix, each column of which contains 5 random numbers generated from a Poisson distribution with mean 10. Now we can find the mean of each column in my_pois using the colMeans() function. Store the result in a variable called cm.

Back

...

Front

Each probability distribution in R has an r* function (for "random"), a d* function (for "density"), a p* (for "probability"), and q* (for "quantile").

Back

LETTERS

Front

a predefined variable in R containing a vector of all 26 letters of the English alphabet.

Back