250+ TOP MCQs on Simulation and Answers

R Programming Language Multiple Choice Questions on “Simulation”.

1. ________ generate random Normal variates with a given mean and standard deviation.
a) dnorm
b) rnorm
c) pnorm
d) rpois

Answer: b
Clarification: The “r” function is the one that actually simulates random numbers from that distribution.

2. Point out the correct statement?
a) R comes with a set of pseudo-random number generators
b) Random number generators cannot be used to model random inputs
c) Statistical procedure does not require random number generation
d) For each probability distribution there are typically three functions

Answer: a
Clarification: R allows you to simulate from well known probability distributions like the Normal, Poisson, and binomial.

3. ______ evaluate the cumulative distribution function for a Normal distribution.
a) dnorm
b) rnorm
c) pnorm
d) rpois

Answer: c
Clarification: p stands for cumulative distribution.

4. _______ generate random Poisson variates with a given rate.
a) dnorm
b) rnorm
c) pnorm
d) rpois

Answer: d
Clarification: q stands for quantile function (inverse cumulative distribution).

5. Point out the wrong statement?
a) For each probability distribution there are typically three functions
b) For each probability distribution there are typically four functions
c) r function is sufficient for simulating random numbers
d) R comes with a set of pseudo-random number generators

Answer: a
Clarification: There are typically four functions available that start with a “r”, “d”, “p”, and “q”.

6. Which of the following evaluate the Normal probability density (with a given mean/SD) at a point?
a) dnorm
b) rnorm
c) pnorm
d) rpois

Answer: a
Clarification: That point can be a vector of points.

7. _________ is the most common probability distribution to work with.
a) Gaussian
b) Parametric
c) Paradox
d) Simulation

Answer: a
Clarification: Working with the Normal distributions requires using four functions.

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

a)

[1] 0.01874617 -0.18425254 -1.37133055 -0.59916772 0.29454513
[6] 0.38979430 -1.20807618 -0.36367602 -1.62667268 -0.25647839

b)

[1] 22.20356 21.51156 19.52353 21.97489 21.48278 20.17869 18.09011
[8] 19.60970 21.85104 20.96596

c)

Min. 1st Qu. Median Mean 3rd Qu. Max.
18.09 19.75 21.22 20.74 21.77 22.20

d) Error

Answer: a
Clarification: Here we simulate standard Normal random numbers with mean 0 and standard deviation 1.

9. What will be the output of the following R code?

> x <- rnorm(10)
> summary(x)

a)

[1] 0.01874617 -0.18425254 -1.37133055 -0.59916772 0.29454513
[6] 0.38979430 -1.20807618 -0.36367602 -1.62667268 -0.25647839

b)

[1] 22.20356 21.51156 19.52353 21.97489 21.48278 20.17869 18.09011
[8] 19.60970 21.85104 20.96596

c)

Min. 1st Qu. Median Mean 3rd Qu. Max.
18.09 19.75 21.22 20.74 21.77 22.20

d) Error

Answer: c
Clarification: We can modify the default parameters to simulate numbers with mean 20 and standard deviation 2.

10. What will be the output of the following R code?

a) 0.9772499
b) 1.9772499
c) 0.6772499
d) 2.6772499

Answer: a
Clarification: If you wanted to know what was the probability of a random Normal variable of being less than 2, you could use the pnorm() function to do that calculation.

250+ TOP MCQs on Packages and Answers

R Programming Puzzles focuses on “Packages ”.

1. ______ Uses Grieg-Smith method on 2 dimensional spatial data.
a) G.S.
b) g.data
c) G1DBN
d) G2db

Answer: a
Clarification: The function returns a GriegSmith object which is a matrix with block sizes, sum of squares for each block size as well as mean sums of squares. G1DBN is a package performing Dynamic Bayesian Network Inference.

2. ______ finds K best paths in a given graph.
a) kBestShortestPaths
b) kcirt
c) ktrees
d) kmap

Answer: a
Clarification: This package provides some routines to conduct the K-adaptive partitioning (kaps) and recursive partitioning (lrtree) for survival data.

3. ________ is a package for parsing, applying, and manipulating data cleaning rules
a) edr
b) editrules
c) edrGraphicalTools
d) edrtools

Answer: b
Clarification: editrules is a package for parsing, applying, and manipulating data cleaning rules. edrGraphicalTools provides tools for dimension reduction methods.

4. ________ performs class prediction based on microarray data and clinical parameters
a) M3
b) M2
c) MAclinical
d) M5

Answer: b
Clarification: M3 is used for reading M3 files.

5. Which of the following package provide namespace management functions not yet present in base R?
a) stringr
b) namespace
c) nbpMatching
d) messagewarning

Answer: b
Clarification: The package namespace is one of the most confusing parts of building a package. nbpMatching contains functions for non-bipartite optimal matching.

6. Which of the following is used to analyze paleontological time-series?
a) accelerometry
b) parfossil
c) paleoTS
d) nbpMatching

Answer: c
Clarification: This package contains parfossil parallelized functions for palaeoecological and palaeogeographical analysis.

7. __________ is used for the analysis of air pollution data.
a) air
b) openair
c) opena
d) openara

Answer: b
Clarification: Data are typically hourly time series and both monitoring data and dispersion model output can be analysed.

8. Which of the following package contains functions for reading and displaying satellite data for oceanographic applications with R?
a) saves
b) satin
c) saws
d) termstrc

Answer: b
Clarification: Saves is used for faster loading of variables.

9. ______ is used for Visualisation, verification and calibration of ternary probabilistic forecasts.
a) toss
b) termstrc
c) ternvis
d) satin

Answer: c
Clarification: TESS is used for faster simulation of reconstructed phylogenetic trees under time-dependent birth-death processes.

10. _________ uniforms and customizes plots of packages ggplot2, graphics and lattice.
a) uniCox
b) uniPlot
c) unknownR
d) unigraph

Answer: b
Clarification: uniPlot() allows to change parameters of the packages graphics, lattice and ggplot2 and to make these changes persistent over one R session.

250+ TOP MCQs on History of R and Answers

R Programming Language Multiple Choice Questions on “History of R”.

1. In which year R-Core group was formed?
a) 1993
b) 1996
c) 1997
d) 1998

Answer: c
Clarification: In 1996, a public mailing list was created. In 1997, the R Core Group was formed. R is for statistical computing and graphics. It compiles and runs on any operating system. It is free software which can easy to install and configure.

2. Version of R released to the public in 2000 was_________
a) 1.0.0
b) 1.0.3
c) 2.0.1
d) 1.1.0

Answer: a
Clarification: In 2000 version 1.0.0 was released to the public. The other versions are released successively. R is a free software environment for statistical computing and graphics. There is no specified operating system for R.

3. R runs on the ____________ operating system.
a) Linux
b) Windows
c) Ubuntu
d) Any operating system

Answer: d
Clarification: R language runs on any standard computing platform and operating platform. So R can run in any operating system. It compiles and runs on a wide variety of UNIX platforms, Windows and MacOS.

4. The primary source code copyright for R is held by the ___________
a) R Foundation
b) S Foundation
c) R and S foundation
d) C Foundation

Answer: a
Clarification: The copyright for the primary source code for R is held by the R Foundation. The S foundation could not have R primary source code. R is a free software environment for statistical computing and graphics.

5. R is published under the __________ General Public License version.
a) A
b) B
c) C
d) GNU

Answer: d
Clarification: R language is published under the GNU General Public License version. It includes compilers for C, C++, Objective-C and a host of other languages. The following licenses are in use for R or associated software such as packages.

6. You can download “base” R system from _________
a) A
b) B
c) CRAN
d) D

Answer: c
Clarification: You can download from CRAN (Comprehensive R Archive Network). The Base R can be found in CRAN. The base R can be found in R studio. The base R system will be found in R studio.

7. Which of the following packages does not contain in “base” R system?
a) utils, graphics
b) mesh, compiler
c) splines, stats4
d) grDevices, datasets

Answer: b
Clarification: Mesh does not belong to the base R system. The other utils, graphics, compiler, splines, stats4, grDevices, datasets will contain Base R system. There are many other packages also in R studio which were pre-installed.

8. There are more than ________ packages on CRAN that have been developed by users and programmers around the world.
a) 40
b) 400
c) 4000
d) 40000

Answer: c
Clarification: There are more than 4000 packages on CRAN. A package bundles together code, data, documentation, and tests, and is easy to share with others. As of January 2015, there were over 4000 packages available on the Comprehensive R Archive Network, or CRAN, the public clearing house for R packages.

9. At higher level one “limitation” of R is that its functionality is based on __________
a) Consumer demand
b) User contributions
c) User contributions and Consumer demand
d) Lower level contributions

Answer: c
Clarification: Its functionality is based on consumer demand and user contributions. It is only for the higher level. The capabilities of the R system generally reflect the interests of the R user community. However, now some of those communities have adopted R and we are seeing more code being written for those kinds of applications.

10. Which of the following command is used to print an object “x” in R?
a) printf(x)
b) print(x)
c) printx
d) print[x]

Answer: b
Clarification: print(x) command is used to print. Print(x) is the basic syntax for R. We can directly print the variable without print function also. The functions in R are helpful to the user to simplify the problem.

250+ TOP MCQs on Data Types and Answers

R Programming Questions & Answers for Exams focuses on “Data Types”.

1. The four most frequently used types of data objects in R are vectors, matrices, data frames and ________
a) Function
b) Lists
c) Packages
d) Interfaces

Answer: b
Clarification: The four most frequently used types of data objects in R are vectors, matrices, data frames and lists. A list is a generalisation of a vector and represents a collection of data objects.

2. A __________ is a set of elements appearing in rows and columns where the elements are of the same mode whether they are logical, numeric (integer or double), complex or character.
a) Vector
b) Matrix
c) Lists
d) Data frames

Answer: b
Clarification: A matrix is a set of elements appearing in rows and columns where the elements are of the same mode whether they are logical, numeric (integer or double), complex or character.

3. What is the simplest way of creating the vector?
a) C function
b) Create
c) Destroy
d) Invalid

Answer: a
Clarification: The simplest way to create a vector is through the concatenation function, c. This function binds elements together, whether they are of character form, numeric or logical.

4. Which function replicates elements of vectors?
a) C
b) Rep
c) Crep
d) Grep

Answer: b
Clarification: The rep function replicates elements of vectors. The seq function creates a regular sequence of values to form a vector. The four most frequently used types of data objects in R are vectors, matrices, data frames and lists.

5. The ________ function creates a regular sequence of values to form a vector.
a) sequel
b) Rep
c) seq
d) Grep

Answer: c
Clarification: The rep function replicates elements of vectors. The seq function creates a regular sequence of values to form a vector. The four most frequently used types of data objects in R are vectors, matrices, data frames and lists.

6. Which function is used to enter in data at the terminal?
a) Scanned
b) Scnn
c) Scan
d) Sccn

Answer: c
Clarification: The scan function is used to enter data at the terminal. This is useful for small datasets but tiresome for entering in large datasets.

7. Computation with vectors is achieved using an element-by-element operation for avoiding _________
a) Loops
b) Functions
c) Packages
d) Interfaces

Answer: a
Clarification: Computation with vectors is achieved using an element-by-element operation. This is useful when writing code because it avoids ’for loops’.

8. To bind a row onto an already existing matrix, the ______ function can be used.
a) Rbind
b) Sbnd
c) Gbind
d) Sbind

Answer: a
Clarification: To bind a row onto an already existing matrix, the rbind function can be used. The scan function is used to enter data at the terminal.

9. Which of the following is a 3-dimensional dataset?
a) Eris
b) Iris
c) Toris
d) Iris

Answer: b
Clarification: The iris dataset is a three dimensional dataset. One dimension is represented for each species: Setosa, Versicolor and Virginica.

10. Which dimension corresponds to the explanatory variables collected for each species?
a) First
b) Second
c) Third
d) Fifth

Answer: b
Clarification: The second dimension corresponds to the explanatory variables collected for each species. The third dimension corresponds to the species.

11. Using the ________ vector, we create a species factor and bind it to the columns of iris.df.
a) snames
b) rnames
c) jnames
d) fnames

Answer: a
Clarification: Using the Snames vector, we create a species factor and bind it to the columns of iris.df. The iris dataset is a three dimensional dataset.

250+ TOP MCQs on Functions and Answers

R Programming Language Multiple Choice Questions on “Functions”.

1. Which of the following is apply function in R?
a) apply()
b) tapply()
c) fapply()
d) rapply()

Answer: b
Clarification: Functions can be passed as arguments to other functions.

2. Point out the correct statement?
a) Writing functions is a core activity of an R programmer
b) Functions are often used to encapsulate a sequence of expressions that need to be executed numerous times
c) Functions are also often written when code must be shared with others or the public
d) All of the mentioned

Answer: d
Clarification: It represents the key step of the transition from a mere “user” to a developer who creates new functionality for R.

3. Functions are defined using the _________ directive and are stored as R objects.
a) function()
b) funct()
c) functions()
d) fun()

Answer: a
Clarification: In particular, they are R objects of class “function”.

4. What will be the output of the following R code?

> f <- function() {
+             ## This is an empty function
+ }
> f()

a) 0
b) No result
c) NULL
d) 1

Answer: c
Clarification: This function takes no arguments and does nothing.

5. Point out the wrong statement?
a) Functions in R are “second class objects”
b) The writing of a function allows a developer to create an interface to the code, that is explicitly specified with a set of parameters
c) Functions provides an abstraction of the code to potential users
d) Writing functions is a core activity of an R programmer

Answer: a
Clarification: Functions in R are “first class objects”, which means that they can be treated much like any other R object.

6. What will be the output of the following R code?

> f <- function() {
+              ## This is an empty function
+ }
> class(f)

a) “function”
b) “class”
c) “procedure”
d) “system”

Answer: a
Clarification: Functions have their own class.

7. Which of the following R code will print “Hello, world!”?
a)

> f <- function() {
+              cat("Hello, world!n")
+ }
> f()

b)

>  f <- function() {
+              cat("Hello, World!n")
+ }
< f()

c)

> f <- function() {
+             cat("Hello world!n")
+ }
>>= f()

d)

> f <- function() {
-             cat("Hello world!n")
+ }
<= f()

View Answer

Answer: a
Clarification: This function has a non-trivial function body.

 

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

> f <- function(num) {
+ for(i in seq_len(num)) {
+               cat("Hello, world!n")
+ }
+ }
> f(3)

a)

Hello, world!
Hello, world!

b)

Hello, world!
Hello, world!
Hello, world!

c)

d)

Hello, world!
Hello, world!
Hello, world!
Hello, world!

View Answer

Answer: b
Clarification: In general, if you find yourself doing a lot of cutting and pasting, that’s usually a good sign that you might need to write a function.

 

9. What will be the output of the following R code?

> f <- function(num) {
+ hello <- "Hello, world!n"
+ for(i in seq_len(num)) {
+                    cat(hello)
+ }
+                    chars <- nchar(hello) * num
+                    chars
+ }
> meaningoflife <- f(3)
> print(meaningoflife)

a) 32
b) 42
c) 52
d) 46

Answer: a
Clarification: This function returns the total number of characters printed to the console.

250+ TOP MCQs on Simulation and Answers

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.