0% found this document useful (0 votes)
77 views21 pages

Welcome To Cmpe140 Final Exam: Studentid

The document provides an introduction to a course titled "Introduction to Computing for Economics and Management" with the course code CMPE140 offered in Spring 2016. It includes sections on exams, assignments, and grading policy. The summary focuses on the key details: 1) The document is an introduction to a computing course for economics and management students titled "Introduction to Computing for Economics and Management" with course code CMPE140. 2) It provides information on exams, assignments, and the grading policy for the course offered in Spring 2016. 3) The introduction, course code, semester, and sections on exams, assignments, and grades are the most essential details mentioned.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
77 views21 pages

Welcome To Cmpe140 Final Exam: Studentid

The document provides an introduction to a course titled "Introduction to Computing for Economics and Management" with the course code CMPE140 offered in Spring 2016. It includes sections on exams, assignments, and grading policy. The summary focuses on the key details: 1) The document is an introduction to a computing course for economics and management students titled "Introduction to Computing for Economics and Management" with course code CMPE140. 2) It provides information on exams, assignments, and the grading policy for the course offered in Spring 2016. 3) The introduction, course code, semester, and sections on exams, assignments, and grades are the most essential details mentioned.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

Introduction to Computing for Economics and

Management
CMPE140 – Spring 2016

Exam

Welcome to CMPE140 Final Exam

StudentID *

 Write here

What is X, Y and Z? *

We store the 1 midterm and 3 quiz grades of 100 students in GRADES.txt. First we want to read
the 㐰㈠le in the matrix form and then obtain its elements line-by-line.

We write the following code:

matrix(X("GRADES.txt"), ncol=Y,byrow=TRUE) 
Z("GRADES.txt") 

X=read.table, Y=4, Z=readline

X=scan, Y=100, Z=readline

X=scan, Y=4, Z=readLines

X=read.table, Y=100, Z=readLines


Which one is the correct code to perform that task? *

10000 random numbers following normal distribution has been created. In order to plot the
histogram, we de㐰㈠ne an x-axis range of (-10,10) and the data intervals are supposed to be of
length 0.10.

x<-rnorm(10000)

hist(x,range=c(-10,10), by=0.10))

x<-rnorm(10000)

hist(x,breaks=(-10,10, 0.10))

x<-rnorm(10000)

hist(x,breaks=seq(-0.10, 0.10, 10))

x<-rnorm(10000)

hist(x,breaks=seq(-10, 10, 0.10))

What is the output if the input vector is c(2,4,11,16,23)? *

(hint: %% is the modulo operator in R. This operation 㐰㈠nds the remainder after division of one
number by another. For example, 5%%2 is 1. )
Consider the following function:

 modula.generator <‐ function(vec){ 
  container.vec <‐ vector() 
   
  for(i in 1:length(vec)){ 
    if(vec[i] %% i == 2){ 
      container.vec <‐ c(container.vec,vec[i]) 
      } 
    } 
  return(container.vec) 
}

What is the output if the input vector is c(2,4,11,16,23)?


4 23

24

11

2 11 16

What is the output if the following code script is executed? *

 func <‐function(n){ 
  i<‐1 
  sum<‐0 
  while(i<n){ 
    sum<‐sum +i 
    i<‐i+1 
  } 
  repeat{ 
    if(sum%%2==0){ 
      break 
    } 
    sum<‐sum‐1 
  } 
  return(sum) 
}

func(6)

(hint: %% is the modulo operator in R. This operation 㐰㈠nds the remainder after division of one
number by another. For example, 5%%2 is 1. )

15

14

10

20
Which of the matrix operations, in terms of an R code, does the above code perform? *

     [,1] [,2] [,3] 
[1,]    1    3    2 
[2,]    4    6    5 

Matrix A is given above. Also B matrix is de㐰㈠ned properly.

 for(i in 1:dim(A)[2]){ 
  for(j in 1:dim(A)[1]){ 
    B[i,j]<‐A[j,i] 
  } 
}

By carefully inspecting the information given, which of the matrix operations, in terms of an R
code, does the above code perform?

B <- inverse(A)

B <- apply(A)

B <- t(A)

B <- diag(A)

Which one is the correct form of code to perform these operations? *

Risk premium on lending is the interest rate charged by banks on loans to private sector
customers minus the “risk free” treasury bill interest rate
at which short-term government securities are issued or traded in the market. In some countries
this spread may be negative,
indicating that the market considers its best corporate clients to be lower risk than the
government.

An analyst 㐰㈠nds the corresponding data below for 5 di㈷㜶erent countries (Canada, USA, Brazil, UK
and Switzerland) for the time period of 2011 to 2014.

 data <‐ c(2.1, 2.0, 2.0, 2.1, 3.2, 3.2, 3.2, 3.2, 32.2, 28.6, 18.4, 20.5, ‐0.01, 0.2, 0.2,
But the problem is the data is given in a vector form. The analyst wants to convert the data into a
matrix called RPonL with the years on the columns
and the countries placed in the rows. After that, she is asked to 㐰㈠nd the mean of the risk
premiums for each countries and re㌮㌷ect the results
in a column in the existing matrix.

RPonL <- matrix(data, byrow=TRUE)

RPonL <- cbind(RPonL, colMeans(RPonL))

RPonL <- matrix(data,nrow=5)

RPonL <- cbind(RPonL,rowMeans(RPonL))

RPonL <- matrix(data,nrow=4,bycol=TRUE)

RPonL <- cbind(RPonL,colMeans(RPonL))

RPonL <- matrix(data, ncol=4, byrow=TRUE)

RPonL <- cbind(RPonL, rowMeans(RPonL))

According to the following code, which student(s) is(are) indicated as slim? *

You are given the data frame, student.frame:

       Name Height  Weight  BMI 
1   Mahmut   1.72     68   22.99 
2      Ece   1.76     67   21.63 
3    Sevde   1.64     59   21.94 
4    Deniz   1.74     64   21.14 
5     Berk   1.79     73   22.78 
6  Alperen   1.85     81   23.67 
7   Melike   1.81     78   23.81 
8     Bora   1.68     75   26.57 
9     Irem   1.89     84   23.52 
10    Onur   1.65     70   25.71

According to the following code, which student(s) is(are) indicated as slim?

ifelse(student.frame$BMI<21.5,"Slim","Normal") 
Deniz and Ece

Deniz

Mahmut, Ece, Sevde, Berk, Alperen, Melike, Bora, Irem and Onur

Bora

Which ones are NOT true? *

i. It is impossible to overwrite a changed data set into an existing 㐰㈠le with write.table.
ii. We can download graphics both in png and pdf format.
iii. We can specify the seperator for the write.table command.

i, iii

iii

ii, iii

Which of the following is a reasonable explanation for the warning message? *

You have information about bank accounts of 10 people (for research purposes). Each has one
account at First Bank and one account at Great Bank. The vectors “㐰㈠rst_bank” and “great_bank”
contain the amounts at First Bank and Great Bank, respectively. When you sum them and assign
the value to the vector “net”, you received the following warning message, though the vector
“net” has been created with 10 numerical values:

Warning message: 
In first_bank + great_bank : 
  longer object length is not a multiple of shorter object length 

You tried to execute a "multiple summation" operation with two vectors which are not

multiple of each other. You should use ordinary summation to get the values.

One of the vectors is recycled. So you should check the lengths of your data.
"net" is too short to be a vector name. Besides, it is not descriptive enough. You should

rename it according to the name conventions.

Probably it is just another case in which R exhibits its oversensitivity about informing the

user. You should just keep working since R will take care of tiny problems.

Which one is the correct coding to get this output? *

Say we have the following text 㐰㈠le, mytext.txt:

123 
a b 36 
6.6 xyz 

We want to get the following output:

[1]"123" "a b 36" "6.6 xyz" 

scan("mytext.txt", sep="", what="\n")

scan("mytext.txt", what="\n")

scan("mytext.txt", sep="\n")

scan("mytext.txt", what="", sep="\n")

What is the output of the function if the input vector is seq(5,-5,-5)? *

You are given the following function:

 partial.sums <‐ function(vec){ 
  sum.numbers <‐ 0 
  sums.seq <‐ vector() 
   
  for(i in 1:length(vec)){ 
    sum.numbers <‐ sum.numbers + vec[i] 
    sums.seq <‐ c(sums.seq,sum.numbers) 
  } 
  return(sums.seq) 
}

550

50

5 0 -5

55

Which graph is obtained by the following code? *

You are given the heights and weights of a group of students:

     Name  Height Weight  
      Ece   1.76    67         
     Irem   1.64    59         
    Deniz   1.74    64         
     Berk   1.79    73         
  Alperen   1.85    81          
   Melike   1.81    78          
     Bora   1.68    75          
     Onur   1.89    84 

Which graph is obtained by the following code?

par(mfcol=c(1,2)) 
pie(sales,col=rainbow(6)) 
barplot(sales,las=2) 
par(mfrow = c(1,1))
What is the correct output if the following code script is executed? *
myfunction<‐function(vector){ 
  i<‐1 
  count <‐0 
  while(i<=length(vector)){ 
    if(i > vector[i]){ 
      vector[i]<‐0 
    } 
    i<‐i+1 
  } 
  vector<‐vector[vector>0] 
  return(vector) 
}

myfunction(c(6,-1,3,5,-4,12,4,10))

-1 -4

10 4 12 -3 5 3 -1 6

6 3 5 12 4 10

6 3 5 12 10

Which of the code scripts generates the following figure? *

Consider we have following data frame.

Name   Height  Weight  BMI   above22.5 
Can   1.70   65   22.49   FALSE 
Cem   1.75   66   21.55   FALSE 
Hande   1.62   61   23.24   TRUE 
Lale   1.76   64   20.66   FALSE 
Arda   1.78   63   19.88   FALSE
plot(person.data)

plot(person.data[1,4],col=ifelse(person.data$above22.5,"red","green"))

plot(person.data[2:5],col=c("green","red"))

plot(person.data[,2:5],col=ifelse(person.data$above22.5,"red","green"))

Which of the following is false? *

The ages of 13 children in a neighborhood are assigned to a vector named “ages”:

ages <‐ c(7,8,8,9,10,12,13,14,15,15,16,16,17)

Here is the boxplot that summarizes the data:


The top of the box corresponds to 15 which splits o㈷㜶 the lowest 75% of the data from the

highest 25%.

The bold line segment corresponds to 12.3 since it is the mean of the data set.

If there was another child in the set with age 13, the boxplot would change.

The bottom of the box corresponds to 9 which splits o㈷㜶 the lowest 25% of the data from

the highest 75%.

Which one of the following is the value of the vector "ordered.vector"? *

my.vector <‐ c(37,15,21,4) 
my.vector <‐ sort(my.vector) 
ordered.vector <‐ order(my.vector[c(4,2,1,3)])
4 15 21 37

3241

1234

4213

Which of the following codes should be run to view the eye color distribution of black-haired male
students and the hair color distribution of blue-eyed female students side by side? *

“HairEyeColor” is one of the built-in data sets in R. In the array the hair and eye color of the
students in a statistics class is stored. Below is the content of the array:

, , Sex = Male 

       Eye 
Hair    Brown Blue Hazel Green 
  Black    32   11    10     3 
  Brown    53   50    25    15 
  Red      10   10     7     7 
  Blond     3   30     5     8 

, , Sex = Female 

       Eye 
Hair    Brown Blue Hazel Green 
  Black    36    9     5     2 
  Brown    66   34    29    14 
  Red      16    7     7     7 
  Blond     4   64     5     8 

par(mfrow=c(1,1))

pie(HairEyeColor[1,1])

pie(HairEyeColor[2,2])

par(mfrow=c(1,2))

pie(HairEyeColor[1,,1])

pie(HairEyeColor[,2,2])
par(mfrow=c(1,2))

pie(HairEyeColor[,1,1])

pie(HairEyeColor[,2,2])

par(mfrow=c(1,1))

pie(HairEyeColor[1,1,],HairEyeColor[2,,2])

What must be the correct X and Y? *

The following code script will be used to 㐰㈠nd the 㐰㈠bonacci numbers until a positive number n.

 fibos<‐function(n){ 
  i<‐3 
  fibonacci.numbers<‐c(1,1) 
  fibo.number<‐2 
  while(X<=n){ 
    fibonacci.numbers[i]<‐fibo.number 
    fibo.number <‐ fibo.number+Y 
    i<‐i+1 
  } 
  return(fibonacci.numbers) 
}

㐰㈠bos(20)

X = 㐰㈠bo.number , Y = 㐰㈠bonacci.numbers[i-1]

X = i, Y = 㐰㈠bonacci.numbers[i]

X = 㐰㈠bo.number , Y = i

X = i , Y = 㐰㈠bonacci.numbers[i-1] + 㐰㈠bonacci.numbers[i-2]

Which statement is false? *

read.table() and scan() can read data from web URLs.


scan() can read text 㐰㈠les consisting of letters without specifying what=""

write.table() is a conveniant way to save data to a 㐰㈠le.

scan() can be used to read input from keyboard.

The output of which of the following codes is the most suitable if we want to view and compare
the boxplots of the given data? *

A class of 8 students is divided into two sections. We have the grades of their 㐰㈠rst maths
midterm and their birth years stored in the vectors below:

grades_section_1 <‐ c(90,80,73,20) 
grades_section_2 <‐ c(88,36,65,29) 
birth_year<‐ c(1994,1994,1995,1993,1994,1994,1995,1994)

par(mfrow=c(1,2))

boxplot(grades_section_1,grades_section_2)

boxplot(birth_year)

par(mfrow=c(1,1))

boxplot(grades_section_1,grades_section_2,birth_year)

par(mfrow=c(1,1))

boxplot(grades_section_1,grades_section_2,birth_year,ylim=c(20,1993))

par(mfrow=c(1,3))

boxplot(grades_section_1)

boxplot(grades_section_2)

boxplot(birth_year)

What is the value of C? *


(hint: %*% is the matrix multiplicator. )
aa.txt 
1 0 0 0  

0 0 0 1 
bb.txt 
1 2 3 4 5  
6 7 8 

A <‐ matrix(scan("aa.txt"), ncol=3, byrow=TRUE) 
B <‐ matrix(scan("bb.txt"), ncol=3, byrow=TRUE) 
C <‐ A%*%B 

123

456

789

123456789

001

010

100

987

654

321

Suppose John is replaced by Ramsay, which one of the below replaces John with Ramsay? *

A list holds information about a student:

 s1 <‐ list(Name="Arya",Age=16,Class=10,Gender="F",Teachers=c("John","Emilia"))

s1[[5]] <- "Ramsay"


replace(s1,"John","Ramsay")

s1[5] <- "Ramsay"

s1[[5]][1] <- "Ramsay"

Which of the codes can be used for this purpose? *

We have two data frames:

stud.grade 
   Name MT1 MT2 
1   Cem  65  58 
2   Ali  80  85 
3 Burcu  55  75 
  
stud.info 
   Name Dept Year 
1   Ali   EC    2 
2 Burcu   IE    4 
3   Cem   EE    3 

We want to merge these two data frames into one which has both the info about and grades of
the same student.

Which of the codes can be used for this purpose?


I. merge(stud.info,stud.grade,by=”Name”)
II. stud.grade<-cbind(“ID”=1:3,stud.grade)
stud.info<-cbind(“ID”=1:3,stud.info)
merge(stud.info,stud.grade,by=”ID”)
III. cbind(stud.info,stud.grade)

I, II, III

I, II

II, III

Which command finds the grand average of all numbers? *


A list is formed as follows:

 newlist <‐ list(c(1,2,3),c(4,5,6))

mean(lapply(newlist,mean))

mean(sapply(lapply(newlist,mean),sum))

lapply(newlist,mean)

sapply(newlist,mean)

Which one of the commands below can be used to get number 11? *

The following commands are executed:

a <‐ list(c(1,2,3),c(4,5,6)) 
b <‐ list(c(7,8,9),c(10,11,12)) 
d <‐ list(a,b)

d[[4]][2]

d[[2]][[2]][2]

d[11]

d[[2]][5]

Which one is the most convenient way to read in a rectangular grid of data from a text file? *

readline()

read.table()

scan()
readLines()

Which of the following should be in the dashed line? *

In linear algebra, a circulant matrix is a special kind of Toeplitz matrix where each row vector is
rotated one element to the right relative to its predecessor row vector (i.e. a row is constructed
by shifting the upper row to the right by 1 element). In numerical analysis, circulant matrices are
important because they are diagonalized by a discrete Fourier transform, hence linear equations
that contain them may be quickly solved using a fast Fourier transform. An example of such a
matrix is given below:

     [,1] [,2] [,3] [,4] 
[1,]    1    2    3    4 
[2,]    4    1    2    3 
[3,]    3    4    1    2 
[4,]    2    3    4    1 

In this question, the aim is to create the nxn circulant matrix called CRC by using the X vector.
The 㐰㈠rst row of the CRC is the X vector and the other rows are created by shifting the 㐰㈠rst row.

Below, the code to construct CRC is provided with a missing line.

 for(i in 1:length(X)){ 
  ‐ ‐ ‐ ‐ ‐ ‐ ‐ ‐ 
}

CRC[length(X) - i +1,] <- c(X[c(i:length(X))],X[c(1:i-1)])

CRC[i,] <- c(X[(1:(length(X)-i+1))],X[-(1:(length(X)-i+1))])

CRC[i,] <- c(X[c(i:length(X))],X[c(1:i-1)])

CRC[i,] <- c(X[-(1:(length(X)-i+1))],X[(1:(length(X)-i+1))])

In which lines, did Ali make a mistake? *

Ali has a data frame “grade” which keeps names, midterm and 㐰㈠nal results and number of
absent days of 50 students respectively.
With that data Ali 㐰㈠rst adds a column for absence point which is calculated as: students are
ordered from the least absent to the most.
Then the 㐰㈠rst student gets 100, the second 98, the third 96, etc.
Then he wants to calculate the total grade of each student with

total=mt*0.4+final*0.5+abs*0.1 

After he gives the total points, he wants to delete the last 5 students from the list as they failed
the course. In order to do these jobs, Ali writes the below code:

(I)  grade<-grade[order(grade[[4]]),]
(II) grade[[5]]<-seq(100,0,-2)
(III) grade[6,]<-grade[2,]*0.4+grade[3,]*0.5+grade[5,]*0.1
(IV) grade<-grade[order(grade[[6]],decreasing=T),]
(V)  grade<-grade[-1:-5,]

II, IV

I, III

III, V

I, IV

Which of the following does the increment (by 10) and also ensures that nobody will have a final
score higher than 100? *

The instructor of cmpe 140 course is impressed by the performance of students such that he/she
wants to add extra 10 points to the 㐰㈠nal scores of everyone whose 㐰㈠nal score is higher than
his/her midterm score. Final and midterm scores are stored in the vectors named “㐰㈠nals” and
“midterms”.

㐰㈠nals[㐰㈠nals > midterms] <- 㐰㈠nals[㐰㈠nals > midterms] + 10

㐰㈠nals[㐰㈠nals > 100] <- 100

㐰㈠nals[㐰㈠nals >> midterms] <- 㐰㈠nals[㐰㈠nals >> midterms] + 10

㐰㈠nals[㐰㈠nals >> 100] <- 100

㐰㈠nals[,㐰㈠nals > midterms] <- 㐰㈠nals[,㐰㈠nals > midterms] + 10

㐰㈠nals[,㐰㈠nals > 100] <- 100

㐰㈠nals[㐰㈠nals > midterms,] <- ifelse(㐰㈠nals - midterms < 0, +10, 0)


㐰㈠nals[㐰㈠nals > 100,] <- 100

In which steps did Aslı make a mistake? *

Aslı has data which contain the students’ names and grades.

Name   MT1   MT2 


Ali  65  60 
Burcu  80  95 
Cem    55  75 

Aslı has to 㐰㈠nd students who are eligible to take the 㐰㈠nal exam and store them as a Boolean
entry in Eligible column . In order to take the 㐰㈠nal exam one has to have an average above 65. In
order to 㐰㈠nd these students Aslı follows these steps :

I. Aslı creates a matrix “Grade” which stores the data and has columns “Name”,”MT1″ and “MT2”
respectively.
II. She adds a column “Avg” which holds the average grades of students by using Grade$Avg<-
(Grade[[2]]+Grade[[3]])/2
III. Then she adds a column “Eligible” by using Grade$Eligible<-ifelse(Grade[[4]]>65,T,F)

II

All steps are correct.

I, II, III

Submit

You might also like