This set of R Programming Questions for entrance exams focuses on “Simulation – 2”.

1. _________ ensures reproducibility of the sequence of random numbers.

a) sets.seed()

b) set.seed()

c) set.seedvalue()

d) all of the mentioned

View Answer

Explanation: 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) All of the mentioned

View Answer

Explanation: 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

View Answer

Explanation: 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

View Answer

Explanation: 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) None of the mentioned

View Answer

Explanation: The sample() function can be used to draw random samples from arbitrary vectors.

6. What will be the output of the following 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 ...

Explanation: 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) All of the mentioned

View Answer

Explanation: It is possible to generate random numbers from other probability distributions like the Poisson.

8. What will be the output of the following code ?

> rpois(10, 1)

a)

[1] 7 0 1 1 2 1 1 4 1 2

b)

[1] 0 8 1 1 2 1 1 4 1 2

c)

[1] 0 0 1 1 2 1 1 4 1 2

d) All of the mentioned

View Answer

Explanation: 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) all of the mentioned

View Answer

Explanation: rpois(10, 20) give counts with a mean of 20.

10. What will be the output of the following 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) All of the mentioned

View Answer

Explanation: The above code computes the outcome via the linear model.

**Sanfoundry Global Education & Learning Series – R Programming Language.**

Here’s the list of Best Reference Books in R Programming Language.

__Here is complete set of 1000+ Multiple Choice Questions and Answers__.