The Open University of Hong Kong
1
Quiz 01 STAT S261F
Part 1: Multiple choice
1. Let A is a matrix, which of the following command is used to estimate column means.
a. mean(A)
b. apply(A, 1, “mean”)
c. apply(A, 2, mean)
d. apply(A, 1, mean)
2. Using the following matrix, A and B, which command is used to find C matrix based on
matrices A and B.
= [
]; = [
]; C= [
]
a. A %*% B
b. 2*A %*% B
c. A %+% 2*B
d. A %*% B*2
3. The estimation error of the models is considered in which Big data V?
a. Volume
b. Velocity
c. Variety
d. Veracity
4. The extraction of data from a database is the responsibility of?
a. Data Engineer
b. Database Administrator
c. Data Scientist
d. Business Intelligence Analyst
5. In which of the following step results are computed using numerical technique on data?
a. Data Preparation
b. Model Planning
c. Model Building
d. Communicate Results
6. Which method is used to run iterations until a certain rule is true?
a. For loop
b. While loop
c. If-else statement
d. Switch function
7. Which of the following is not considered to be a significant skill for a data scientist?
a. Programming skills
b. Business insight skills
c. Non adaptiveness
d. Quantitative and analytical skills
8. Which of the following function is often used to perform numeric operations on the data
frame?
a. Apply()
b. Format()
c. Cat()
d. Tapply()
9. How many errors in the following R code?
The Open University of Hong Kong
2
x <- c(2,5,3,9,8,11,6)
count -- 0
for (val in x) {
if(val %% 2 = 0) count = count+1
print(count)
a. 3
b. 5
c. 4
d. None
10. Which of the following command is used to generate a number of auto character values?
a. Cat()
b. Paste()
c. Format()
d. Subsetting()
Part 2: Short Questions
1. Provide the R code to make the following matrix. (Marks 2)
Answer
mat=matrix(c("A","B","C","D","E",60, 41, 38, 56, 24, 84 , 9 , 1 ,64 ,42 ,95 ,87,
79, 34 ,11 ,36, 35, 57, 67, 33),ncol = 5, byrow = TRUE)
colnames(mat)=c("first","second","third","forth","fifth")
rownames(mat)=c("1st","2nd","3rd","4th","5th")
mat
2. Make a function with name “estimates” which only take “x” as input and provide values of
“m” and “s” where their mathematical expression are given below.
=
∑
=
; =
∑ (−)
=
Moreover, report “m” and “s” by using x=c(12,34,46,43,23,34,13,24,16). (Marks 3)
Answer
estinmates=function(x){
n=length(x)
mu=sum(x)/n
s=(sum(x-mu)^2)/(n-1)
cbind(mu,s)
}
The Open University of Hong Kong
3
x=c(12,34,46,43,23,34,13,24,16)
estimates(x)
3. Form a data frame based on the following two vectors named by “weight” and “section”.
weight=c(60, 41, 38, 56, 24, 84 , 9 , 1 ,64 ,42 ,95 ,87, 79, 34 ,11 ,36, 35, 57, 67, 33)
section=c("Red","Blue","Green","Blue",
"Blue","Blue","Red","Blue","Green","Red","Blue","Red","Blue","Green","Green","Blue",
"Red","Blue","Green","Green")
Find the average weight of the students of red section?
Find the average weight of the students of blue and green sections? (Marks 2)
Answer
data=data.frame(weight,section)
mean(data$weight[section=="Red"])
mean(data$weight[section!="Red"])
4. Write a R code for BMI value to assign following nutritional status. (Marks 3)
BMI Nutritional Status
Below 18.5 Under Weight
18.5-24.9 Normal Weight
25.0-29.9 Pre-obesity
Above 30 Obesoity
Answer
if(BMI<18.5){
ns="under weight"
}else if(BMI>=18.5|BMI<=24.9){
ns="normal weight"
}else if(BMI>=25|BMI<=29.9){
ns="pre-obesity"
}else if(BMI>30){
ns="obesity"
}
学霸联盟