logo Hurry, Grab up to 30% discount on the entire course
Order Now logo
767 Times Downloaded

Ask This Question To Be Solved By Our ExpertsGet A+ Grade Solution Guaranteed

expert
Mason RamirezSociology
(5/5)

870 Answers

Hire Me
expert
Mason RamirezzTechnical writing
(4/5)

979 Answers

Hire Me
expert
Vinay WahwaAccounting
(5/5)

590 Answers

Hire Me
expert
James BeckettBusiness
(5/5)

881 Answers

Hire Me
R Programming
(5/5)

function seq() can be used to create a sequence of numbers. For instance, seq(a,b) makes a vector of integers between a and b.

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS

This assignment continues in-class work on Module  41 (R labs).  This assignment is based on labs from Chapter 2 (Section 2.3) of the textbook.  Students can use it as a reference and also they can use R help (?command name) for getting information on the syntax of the commands implemented. This assignment is based on the Lab (Section 2.3) of the ISLR textbook – students are encouraged to use this text during the work on this assignment.

The assignment contains 7 questions.

1. The function seq() can be used to create a sequence of numbers. For instance, seq(a,b) makes a vector of integers between a and b. 

> x=seq (1 ,10)

> x

 [1]  1  2  3  4  5  6  7  8  9 10

Typing 1:10  is a  shorthand for seq(1,10) for integer arguments.

>  x=1:10

>  x

 [1]  1  2  3  4  5  6  7  8  9 10

There are many other options: for instance, seq(0,1,length=10) makes a sequence of 10 numbers that are equally spaced between 0 and 1. Type 50 numbers that are equally spaced between negative π and positive π (symbol pi in R).

Question 1: 

What is the number which is third in this sequence:

a.   -2.757                       b.    -2.885                      c.     -3.013                d. None of above 

2. We will now create some more sophisticated plots. The contour() function produces a contour plot in order to represent three-dimensional data; it is like a topographical map. It takes three arguments: 

1. A vector of the x values (the first dimension),

2. A vector of the y values (the second dimension), and

3. A matrix whose elements correspond to the z value (the third dimension) for each pair of (x,y) coordinates. This function can be set up by using the command outer.

 

To learn more about the parameters of this command take a look at the help file by typing ?contour and ?outer. Plot contours for function f=cos(y)/(1+x^2). Save this file as in a  jpeg format and increase to have all contours appear with the relevant values. 

Question 2: 

What is the value for the lower contour on the figure provided by R for y< -π/2?

a.   -0.8                       b.    0.2                      c.     -0.5                d. None of above 

3. Plot the contours for f – transposed f (t(f) return the transposed matrix of f) divided by 2. Check what is a syntax of the parameter “levels”. Set levels = 15.

Question 3: What is the value for the upper contour on the figure provided by R for right quarter of the figure?

a.   -0.5                       b.    0.2                      c.     0.5                d. None of above 

4.  The image() function works the same way as contour(), except that it  produces a color-coded plot whose colors depend on the z value. This is known as a heatmap, and is sometimes used to plot temperature in weather forecasts. 

Implement command image for the function defined in exercise 3.  Compare it with the contour map from Exercise 3.

Question 4: What color corresponds to the lowest values of function fa?

a.   red                        b.    white                      c.     yellow                d. None of above 

 

5. Alternatively, persp() can be used to produce a three-dimensional plot. The arguments theta and phi control the angles at which the plot is viewed. Implement command persp for the function defined in exercise 3 for angles theta and phi 30 and 40 degrees respectively.  Compare it with the contour map from Exercise 3.

Question 5: What type of extremes of function fa can be observed in cross-section y for smallest value of y?

a.   minimum                        b.    inflection point                      c.     maximum                d. None of above 

 

6.    Indexing data. We often wish to examine part of a set of data. Suppose that our data is  stored in the matrix A.

> A=matrix (1:16 ,4 ,4)

> A

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

[1,]    1    5    9   13

[2,]    2    6   10   14

[3,]    3    7   11   15

[4,]    4    8   12   16

We can also select multiple rows and columns at a time, by providing vectors as the indices.

> A[1:3 ,2:4]

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

[1,]    5    9   13

[2,]    6   10   14

[3,]    7   11   15

> A[1:2 ,]

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

[1,]    1    5    9   13

[2,]    2    6   10   14

> A[ ,1:2]

     [,1] [,2]

[1,]    1    5

[2,]    2    6

[3,]    3    7

[4,]    4    8

R treats a single row or column of a matrix as a vector:

> A[1,]

[1]  1  5  9 13

 

Create matrix 4x4 were elements are 16 values of standard normal distribution (use set.seed(5)). Print 

A vector , which is the third columns of this matrix.

Questions 6: 

What is the third element of this vector?

a.   -0.285                       b. 0.138         c.     -0.802                d. None of above 

7. The use of a negative sign - in the index tells R to keep all rows or columns except those indicated in the index.  

> A[-c(1,3) ,]

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

[1,]    2    6   10   14

[2,]    4    8   12   16

 

For the matrix created in exercise 6 print the 2x2 submatrix which is from the second and the third column and from the second and the third row of the initial 4x4 matrix.  

Question 7: 

What is the bottom right element of this 2x2 matrix?

a.   0.138          b. -0.603         c.     1.228                d. None of above 

(5/5)
Attachments:

Expert's Answer

767 Times Downloaded

Related Questions

. The fundamental operations of create, read, update, and delete (CRUD) in either Python or Java

CS 340 Milestone One Guidelines and Rubric  Overview: For this assignment, you will implement the fundamental operations of create, read, update,

. Develop a program to emulate a purchase transaction at a retail store. This  program will have two classes, a LineItem class and a Transaction class

Retail Transaction Programming Project  Project Requirements:  Develop a program to emulate a purchase transaction at a retail store. This

. The following program contains five errors. Identify the errors and fix them

7COM1028   Secure Systems Programming   Referral Coursework: Secure

. Accepts the following from a user: Item Name Item Quantity Item Price Allows the user to create a file to store the sales receipt contents

Create a GUI program that:Accepts the following from a user:Item NameItem QuantityItem PriceAllows the user to create a file to store the sales receip

. The final project will encompass developing a web service using a software stack and implementing an industry-standard interface. Regardless of whether you choose to pursue application development goals as a pure developer or as a software engineer

CS 340 Final Project Guidelines and Rubric  Overview The final project will encompass developing a web service using a software stack and impleme