R Flashcards

1
Q

sessionInfo()

A

provides information about the operating system, version of R and version of all R packages being used.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How to simulate a random sample for a discrete uniform distribution

A

To generate a vector for sample space S = {1, 2, 3, ….. , 20}: S = 1:20
To simulate 100 values from this sample space: sample(S, 100, replace = TRUE)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

distribution functions

A

The R code for simulating values and calculating probabilities and quantiles from the binomial distribution uses the R functions rbinom, dbinom, pbinom and qbinom. The prefixes r, d, p, and q stand for random generation, density, distribution and quantile functions respectively. (A discrete distribution has a probability mass function rather than a density, but the prefix d is still used.)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Random sample of 100 values from a discrete uniform distribution (1,20)

A
S=1:20
P=sample(S,100,replace=TRUE)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

a) Get a random sample of 100 values from the Bin(20,0.3)
b) Calc P(X=2)

A

a) ```
n=20
p=0.3
rbinom(100,n,p)
~~~

b) dbinom(2,n,p)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Setting a seed

A

set.seed(n)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Graphs

A

hist
curve

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Constructing 95% CI for the mean with unknown variance

A

The R function for a symmetrical 95% confidence interval for the mean with unknown variance is:

t.test(<sample data>, conf=0.95)

For small samples from a non-normal distribution, confidence intervals can be constructed empirically in R using the bootstrap method . For example, a non-parametric 95% confidence interval for the mean could be obtained by:
quantile(replicate(1000,mean(sample(<sample data>,replace=TRUE))), probs=c(0.025,0.975))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly