R Programming Questions for entrance exams focuses on “Simulation”.
1. _________ ensures reproducibility of the sequence of random numbers.
a) sets.seed()
b) set.seed()
c) set.seedvalue()
d) set.value()
Answer: b
Clarification: Setting the random number seed with set.seed() ensures reproducibility of the sequence of random numbers.
2. Point out the correct statement?
a) When simulating any random numbers it is not essential to set the random number seed
b) It is not possible to generate random numbers from other probability distributions like the Poisson
c) You should always set the random number seed when conducting a simulation
d) Statistical procedure does not require random number generation
Answer: c
Clarification: Otherwise, you will not be able to reconstruct the exact numbers that you produced in an analysis.
3. 5 Normal random numbers can be generated with rnorm() by setting seed value to ______________
a) 1
b) 2
c) 3
d) 4
Answer: a
Clarification: set.seed(1) will give 5 normal random numbers.
4. _______ function is used to simulate binary random variables.
a) dnorm
b) rbinom()
c) binom()
d) rpois
Answer: b
Clarification: rbinom() is used to simulate a predictor variable x that is binary instead of having a Normal distribution.
5. Point out the wrong statement?
a) Drawing samples from specific probability distributions can be done with “s” functions
b) The sample() function draws randomly from a specified set of (scalar) objects allowing you to sample from arbitrary distributions of numbers
c) The sampling() function draws randomly from a specified set of objects
d) You should always set the random number seed when conducting a simulation
Answer: b
Clarification: The sample() function can be used to draw random samples from arbitrary vectors.
6. What will be the output of the following R code?
> set.seed(10) > x <- rbinom(100, 1, 0.5) > str(x)
a)
int [1:100] 1 0 0 1 0 0 0 0 1 0 ...
b)
int [1:100] 10 0 01 1 0 0 01 0 1 0 ...
c)
int [1:100] 1 03 0 1 0 0 0 02 1 0 ...
d)
int [1:100] 1 2 3 1 1 0 0 0 1 0 ...
View Answer
Answer: a
Clarification: Setting the random number seed with set.seed() ensures reproducibility of the sequence of random numbers. rbinom() is used to simulate a predictor variable x that is binary instead of having a Normal distribution.
7. __________ distribution is commonly used to model data that come in the form of counts.
a) Gaussian
b) Parametric
c) Poisson
d) Simulation
Answer: c
Clarification: It is possible to generate random numbers from other probability distributions like the Poisson.
8. What will be the output of the following R code?
a)
b)
c)
d)
[1] 0 0 0 0 0 0 0 1 4 1 2
View Answer
Answer: c
Clarification: The above code represents count with mean of 1.
9. Which of the following code represents count with mean of 2?
a) rpois(10, 2)
b) rpois(10, 20)
c) rpois(20, 2)
d) rpois(20, 20)
Answer: a
Clarification: rpois(10, 20) give counts with a mean of 20.
10. What will be the output of the following R code?
> set.seed(20) > x <- rnorm(100) > e <- rnorm(100, 0, 2) > y <- 0.5 + 2 * x + e > summary(y)
a)
Min. 1st Qu. Median Mean 3rd Qu. Max. -6.4080 -1.5400 0.6789 0.6893 2.9300 6.5050
b)
Min. 1st Qu. Median Mean 3rd Qu. Max. -6.4080 -10.5400 0.6789 5.6893 2.9300 6.5050
c)
Min. 1st Qu. Median Mean 3rd Qu. Max. -1.4080 -6.5400 0.6789 0.6893 2.9300 6.5050
d) Error
Answer: a
Clarification: The above code computes the outcome via the linear model.