250+ TOP MCQs on Distribution and Answers

R Programming Language Multiple Choice Questions on “Distribution ”.

1. The _______ and ________ of a discrete random variable is easy to compute at the console.
a) Mean, Variance
b) Variance, Packages
c) Packages, Functions
d) Median, Mode

Answer: a
Clarification: The mean and variance of a discrete random variable are easy to compute at the console. To calculate the mean µ, we need to multiply the corresponding values of x and f and add them.

2. Which of the following simple the square root of σ square?
a) Variance
b) Standard deviation
c) Mean
d) Median

Answer: b
Clarification: Standard deviation is the measure of dispersion of a set of data from its mean. The standard deviation σ is simply the square root of σ square.

3. The abbreviation of Cumulative Distributive Function is ________
a) CDFN
b) CMDF
c) CMD
d) CDF

Answer: d
Clarification: A cumulative distributive function P(x) is the probability of getting some value less than a certain value x. If p(x) will be the density function for a probability distribution, then that will be the cumulative distributive function P(x) is calculated as the integral of p(x) over the interval −∞ to x.

4. Which function is used to simulate discrete uniform random variables?
a) Sample
b) Simple
c) Function
d) Variance

Answer: a
Clarification: One can choose an integer at random with the sample function. The general syntax of the simulation of the discrete uniform random variable is a sample (x, size, replace = TRUE).

5. The binomial distribution is based on _______ trial.
a) Einstein
b) Bernoulli
c) Bohr
d) Kepler

Answer: b
Clarification: The binomial distribution is the distribution based on the Bernoulli trial, which is a random experiment in which there are only two possible outcomes: success (S) and failure (F).

6. The corresponding R function for the PMF is __________
a) Trinom
b) Dbinorm
c) Dbinom
d) Fnorm

Answer: c
Clarification: dnorm is the height of the density of a normal curve while dbinom returns the probability of an outcome of a binomial distribution.

7. The corresponding R function for the CDF is __________
a) Dbinom
b) Pbinom
c) Cbinorm
d) Hbinorm

Answer: b
Clarification: The function pbinom is very useful for summing consecutive binomial probabilities. The pbinom function returns the probability that the value of a variable that follows the binomial distribution.

8. Random variables defined via the _______ package.
a) Distri
b) Diestr
c) Distr
d) Diftr

Answer: c
Clarification: Random variables defined via the distr package may be plotted, which will return graphs of the PMF, CDF, and quantile function.

9. MGF means _____________
a) Moment Generating Formulas
b) Movement Generating Formulas
c) Moment Generating Functions
d) Moment Graphic Functions

Answer: c
Clarification: The moment generating function, if it exists in a neighbourhood of zero, determines a probability distribution uniquely.

10. The empirical cumulative distribution function can be called as __________
a) EMCDF
b) EDFC
c) ECDF
d) EGDF

Answer: c
Clarification: The empirical cumulative distribution function is the probability distribution that places into the probability mass. ECDF refers to the empirical cumulative distribution function.

250+ TOP MCQs on Console Input and Evaluation and Answers

R Programming Language Multiple Choice Questions on “Console Input and Evaluation – 1”.

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

a) 1
b) 2
c) 3
d) 5

Answer: a
Clarification: When a complete expression is entered at the prompt, it is evaluated and the result of the evaluated expression is returned.

2. Point out the wrong statement?
a) The grammar of the language determines whether an expression is complete or not
b) The <- symbol is the assignment operator in R
c) The ## character indicates a comment
d) R does not support multi-line comments or comment blocks

Answer: c
Clarification: Unlike some other languages, R does not support multi-line comments or comment blocks.

3. Which of the R following code is example of explicit printing?
a)

b)

c)

d)

> x <- "auto" 
> x <- "auto"

View Answer

Answer: b
Clarification: Print command is used for outputting the value.

 

4. Files containing R scripts ends with extension ____________
a) .S
b) .R
c) .Rp
d) .SP

Answer: b
Clarification: Under many versions of UNIX and on Windows, R provides a mechanism for recalling and re-executing previous commands.

5. Point out the wrong statement?
a) : operator is used to create integer sequences
b) The numbers in the square brackets are part of the vector itself
c) There is a difference between the actual R object and the manner in which that R object is printed to the console
d) Files containing R scripts ends with extension .R

Answer: b
Clarification: They are merely part of the printed output.

6. If commands are stored in an external file, say commands.R in the working directory work, they may be executed at any time in an R session with the command ____________
a) source(“commands.R”)
b) exec(“commands.R”)
c) execute(“commands.R”)
d) exect(“command.R”)

Answer: a
Clarification: For Windows, Source is also available on the File menu.

7. _______ will divert all subsequent output from the console to an external file.
a) sink
b) div
c) exp
d) exc

Answer: a
Clarification: sink() restores it to the console once again.

8. The entities that R creates and manipulates are known as ________
a) objects
b) task
c) container
d) packages

Answer: a
Clarification: These may be variables, arrays of numbers, character strings, functions, or more general structures built from such components.

9. Which of the following can be used to display the names of (most of) the objects which are currently stored within R?
a) object()
b) objects()
c) list()
d) class()

Answer: b
Clarification: During an R session, objects are created and stored by name.

10. Collection of objects currently stored in R is called as ________________
a) package
b) workspace
c) list
d) task

Answer: b
Clarification: All objects created during an R session can be stored permanently in a file for use in future R sessions.

250+ TOP MCQs on Vectorized Operations and Answers

R Programming Language Multiple Choice Questions on “Vectorized Operations ”.

1. Which of the following is example of vectorized operation as far as subtraction is concerned?

a) x+y
b) x-y
c) x/y
d) x–y

Answer: b
Clarification: Subtraction, multiplication and division are also vectorized.

2. Point out the wrong statement?
a) Very less operations in R are vectorized
b) Vectorization allows you to write code that is efficient, concise, and easier to read than in non-vectorized languages
c) vectorized means that operations occur in parallel in certain R objects
d) Matrix operations are also vectorized

Answer: a
Clarification: Many operations in R are vectorized.

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

> x <- 1:4
> y <- 6:9
> z <- x + y
> z

a) 7 9 11 13
b) 7 9 11 13 14
c) 9 7 11 13
d) NULL

Answer: a
Clarification: This is simplest example of adding two vectors together.

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

a) 1 2 3 4
b) FALSE FALSE TRUE TRUE
c) 1 2 3 4 5
d) 5 4 3 1 2 1

Answer: b
Clarification: Another operation you can do in a vectorized manner is logical comparisons.

5. Point out the wrong statement?
a) Dates are represented by the Date class
b) Times are represented by the POSIXct or the POSIXlt class
c) Dates are represented by the DateTime class
d) Times can be coerced from a character string

Answer: c
Clarification: Dates are stored internally as the number of days since 1970-01-01 while times are stored internally as the number of seconds since 1970-01-01.

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

> x <- 1:4
> y <- 6:9
> x/y

a) 0.1666667 0.2857143 0.4444444
b) 0.1666667 0.2857143 0.3750000 0.4444444
c) 0.2857143 0.3750000 0.4444444
d) Error

Answer: b
Clarification: Logical operations return a logical vector of TRUE and FALSE.

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

> x <- matrix(1:4, 2, 2)
> y <- matrix(rep(10, 4), 2, 2)
> x * y

a)

[,1] [,2]
[1,] 10 30
[2,] 20 40

b)

[,1] [,2]
[1,] 10 30
[2,] 30 40

c)

[,1] [,2]
[1,] 20 30
[2,] 20 40

d) Error

Answer: a
Clarification: Matrix operations are also vectorized, making for nicely compact notation.

8. Which of the following code represents internal representation of a Date object?
a) class(as.Date(“1970-01-02”))
b) unclass(as.Date(“1970-01-02”))
c) unclassint(as.Date(“1970-01-02”))
d) classint(as.Date(“1970-02-02”))

Answer: b
Clarification: You can see the internal representation of a Date object by using the unclass() function.

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

> x <- as.Date("1970-01-01")
> x

a) “1970-01-01”
b) “1970-01-02”
c) “1970-02-01”
d) “1970-02-02”

Answer: a
Clarification: Dates are represented by the Date class and can be coerced from a character string using the as.Date() function.

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

> x <- Sys.time()
> class(x)

a) “POSIXct” “POSIXt”
b) “POSIXXt” “POSIXt”
c) “POSIXct” “POSIct”
d) “POSIXt” “POSIXt”

Answer: a
Clarification: Times can be coerced from a character string using the as.POSIXlt or as.POSIXct function.

250+ TOP MCQs on Scoping Rules and Answers

R Programming Language Multiple Choice Questions on “Scoping Rules ”.

1. What will be the output of the following R code snippet?

> lm <- function(x) { x * x }
> lm

a) function(x) { x * x }
b) func(x) { x * x }
c) function(x) { x / x }
d) function { x $ x }

Answer: a
Clarification: When R tries to bind a value to a symbol, it searches through a series of environments to find the appropriate value.

2. Point out the correct statement?
a) The search list can be found by using the searchlist() function
b) The search list can be found by using the search() function
c) The global environment or the user’s workspace is always the second element of the search list
d) R has separate namespaces for functions and non-functions

Answer: b
Clarification: Base package is always the last element.

3. A function, together with an environment, makes up what is called a ______ closure.
a) formal
b) function
c) reflective
d) symmetry

Answer: b
Clarification: The function closure model can be used to create functions that “carry around” data with them.

4. Which of the variable in the following R code is variable?

> f <- function(x, y) {
+            x^2 + y / z
+ }

a) x
b) y
c) z
d) yy

Answer: c
Clarification: This function has 2 formal arguments x and y. In the body of the function there is another symbol z. In this case z is called a free variable.

5. Point out the wrong statement?
a) The order of the packages on the search list does not matter
b) R has separate namespaces for functions and non-functions
c) Users can configure which packages get loaded on startup so if you are writing a function
d) The search list can be found by using the search() function

Answer: a
Clarification: The order of the packages on the search list matters, particularly if there are multiple objects with the same name in different packages.

6. R uses _________ scoping6 0 or static scoping.
a) reflective
b) transitive
c) lexical
d) closure

Answer: c
Clarification: Lexical scoping in R means that the values of free variables are searched for in the environment in which the function was defined.

7. The only environment without a parent is the ________ environment.
a) full
b) half
c) null
d) empty

Answer: d
Clarification: Every environment has a parent environment and it is possible for an environment to have multiple “children”.

8. The ________ for R are the main feature that make it different from the original S language.
a) scoping rules
b) closure rules
c) environment rules
d) closure & environment rules

Answer: a
Clarification: This function never actually uses the argument b, so calling f(2) will not produce an error because the 2 gets positionally matched to a.

9. The _________ function is a kind of “constructor function” that can be used to construct other functions.
a) make.pow()
b) make.power()
c) keep.power()
d) keep.pow()

Answer: b
Clarification: Typically, a function is defined in the global environment, so that the values of free variables are just found in the user’s workspace.

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

> g <- function(x) {
+             a <- 3
+             x+a+y
+          ## 'y' is a free variable
+ }
> g(2)

a) 9
b) 42
c) 8
d) Error

Answer: d
Clarification: Object ‘y’ not found error is displayed.

250+ TOP MCQs on Exploratory Data Analysis and Answers

Advanced R Programming Questions & Answers focuses on “Exploratory Data Analysis”.

1. __________ produces box-and-whisker plots.
a) xyplot
b) dotplot
c) barchart
d) bwplot

Answer: d
Clarification: Bwplot plots a series of vertical box-and-whisker plots where the individual boxplots represent the data subdivided by the value of some factor. Optionally the y-axis may be scaled logarithmically. Dotplot produces Cleveland dot plots. Barchart produces bar plots.

2. __________ produces bivariate scatterplots or time-series plots.
a) xyplot
b) dotplot
c) barchart
d) bwplot

Answer: a
Clarification: xyplot has points that show the relationship between two sets of data. Optionally the y-axis may be scaled logarithmically. dotplot produces Cleveland dot plots. barchart produces bar plots.

3. Annotation of plots in any plotting system involves adding points, lines, or text to the plot, in addition to customizing axis labels or adding titles. Different plotting systems have different sets of functions for annotating plots in this way. Which of the following functions can be used to annotate the panels in a multi-panel lattice plot?
a) points()
b) panel.abline()
c) lines()
d) axis()

Answer: b
Clarification: panel.abline() is one of the most used panel function.

4. ____________ produces one-dimensional scatterplots.
a) xyplot
b) stripplot
c) barchart
d) bwplot

Answer: b
Clarification: This function along with other high-level Lattice functions, respond to a common set of arguments.

5. which of the following functions can be used to finely control the appearance of all lattice plots ?
a) par()
b) print.trellis()
c) splom()
d) trellis.par.set()

Answer: d
Clarification: All high-level function in lattice are generic.

6. What is ggplot2 an implementation of?
a) the Grammar of Graphics developed by Leland Wilkinson
b) 3D visualization system
c) the S language originally developed by Bell Labs
d) the base plotting system in R

Answer: a
Clarification: The ggplot2 package, created by Hadley Wickham, offers a powerful graphics language for creating elegant and complex plots.

7. For barchart and _________ non-trivial methods exist for tables and arrays, documented at barchart.table.
a) scatterplot
b) dotplot
c) xyplot
d) scatterplot & xyplot

Answer: b
Clarification: The numeric methods are equivalent to a call with no left hand side and no conditioning variables in the formula.

8. What is a geom in the ggplot2 system?
a) a plotting object like point, line, or other shape
b) a method for making conditioning plots
c) a method for mapping data to attributes like color and size
d) a statistical transformation

Answer: a
Clarification: The bar geom is used to produce 1d area plots.

9. Logical flag is applicable to which of the following plots?
a) scatterplot
b) dotplot
c) xyplot
d) zyplot

Answer: b
Clarification: Logical flag applicable to bwplot, dotplot, barchart, and stripplot.

10. ___________ is used to determine what is plotted for each group.
a) panel.expose
b) panel.impose
c) panel.superpose
d) panel.depose

Answer: c
Clarification: panel.superpose can be combined with different panel.groups functions.

250+ TOP MCQs on Distribution and Answers

R Programming written test Questions & Answers focuses on “Distribution ”.

1. Two important methods in analysis is differentiation and __________ transformation.
a) Bernoulli
b) Fourier
c) Bohr
d) Rutherford

Answer: b
Clarification: Two important methods in the analysis is differentiation and Fourier transformation. Unfortunately, not all functions are differentiable or have a Fourier transform.

2. Every ________ function has a probability distribution function.
a) Continuous
b) Discrete
c) Categorical
d) Random

Answer: a
Clarification: Every continuous random variable x has a great Probability Density Function (PDF). The PDF can sometimes be greater than 1. This is in contrast to the discrete case.

3. Which package resorts to numerical methods when it encounters a model it does not recognize.
a) destrEx
b) ditrEx
c) distrEx
d) Exdistr

Answer: c
Clarification: distrEx provides some extensions of package distr and further functionalities like var, sd, IQR, mad, median, skewness, kurtosis truncated moments.

4. When µ = ___ and σ = ___ we say that the random variable has a standard normal distribution.
a) 0,1
b) 0,0
c) 1,0
d) 1,1

Answer: a
Clarification: When µ = 0 and σ = 1 we say that the random variable has a standard normal distribution and we typically write Z ∼ norm(mean = 0, sd = 1).

5. Which of the following is the symbol of standard normal PDF?
a) φ
b) #
c) &
d) *

Answer: a
Clarification: The lowercase Greek letter phi (φ) is used to denote the standard normal PDF and the capital Greek letter phi Φ is used to denote the standard normal CDF.

6. The __________ package has functionality to investigate transformations of univariate distributions.
a) Distri
b) Dirtr
c) Distr
d) Hyperbolic

Answer: c
Clarification: The distr package has a functionality to find the transformations of one variable distribution. There are exact results for the ordinary transformations for the standard distributions, and distr takes advantage of these in many cases.

7. Which distribution looks like a norm distribution but with very heavy tails?
a) Simple
b) Discrete
c) Continuous
d) Cauchy

Answer: d
Clarification: The Cauchy distribution looks like a norm distribution but with very heavy tails. The mean (and variance) do not exist, that is, they are infinite.

8. The ________ is represented by the location parameter.
a) Median
b) Mode
c) Mean
d) Variance

Answer: a
Clarification: The median is represented by the location parameter, and the scale parameter influences the spread of the distribution about its median.

9. The ______ parameter influences the spread of the distribution about its median.
a) Scale
b) Mode
c) Mean
d) Variance

Answer: a
Clarification: The scale parameter influences the spread of the distribution about its median. The median is represented by the location parameter.

10. Which distribution comes up a lot in Bayesian statistics because it is a good model for one’s prior beliefs about a population proportion?
a) Bohr
b) Discrete
c) Alpha
d) Beta

Answer: d
Clarification: Beta distribution comes up a lot in Bayesian statistics because it is a good model for one’s prior beliefs about a population proportion.

11. The associated R function is dlogis (x, location = 0, scale = 1) is for _________ distribution.
a) Logistic
b) Linear
c) Discrete
d) Beta

Answer: a
Clarification: The associated R function is dlogis (x, location = 0, scale = 1). The logistic distribution comes up in differential equations as a model for population growth under certain assumptions.

12. The _________ distribution comes up in differential equations as a model for population growth under certain assumptions.
a) Logistic
b) Linear
c) Discrete
d) Beta

Answer: a
Clarification: The associated R function is dlogis(x, location = 0, scale = 1). The logistic distribution comes up in differential equations as a model for population growth under certain assumptions.

13. Which of the following is a distribution derived from the normal distribution?
a) Logistic
b) Lognormal
c) Normal
d) Simple

Answer: b
Clarification: Lognormal distribution is a distribution derived from the normal distribution (hence the name). Its name also says that it is derived from the normal distribution.

14. The associated R function is dlnorm(x, meanlog = 0, sdlog = 1) is for ________ distribution.
a) Logistic
b) Lognormal
c) Normal
d) Simple

Answer: b
Clarification: The associated R function is dlnorm(x, meanlog = 0, sdlog = 1). Lognormal distribution is a distribution derived from the normal distribution (hence the name). Its name also says that it is derived from the normal distribution.

15. The associated R function is dweibull(x, shape, scale = 1) is for _________ distribution.
a) Logistic
b) Lognormal
c) Weibull
d) Simple

Answer: c
Clarification: The associated R function is dweibull(x, shape, scale = 1). There are exact results for ordinary transformations of the standard distributions, and distr takes advantage of these in many cases.