Create a function that takes as input a data table

Assignment Help Computer Engineering
Reference no: EM132118847

R programming

It is possible to approximate the area of any two-dimensional shape using a Monte Carlo technique. To do this, we specify a region of known area that contains the shape, sample uniformly on that region, then multiply the known area by the fraction of the points that fall within the shape we're trying to measure. In this problem you'll write code to carry this out for a circle with radius equal to one. We can compare this to what we already know about the area of circles to see how well our approximation method performs.

(a) Write expressions in R to do the following:

• Create two vectors x and y of length 100, where each is sampled from the Uniform distribution with lower limit -1 and upper limit 1.

• Calculate the proportion of these for which the point (x, y) lies within the unit circle.

• Make a scatter plot of x and y, coloring the points differently depending on whether they're inside the unit circle or not.

• Multiply the proportion by 4 (the area of the square over which we're sampling) to approximate the area inside the circle.

(b) Now use your code from part (a) to write the following functions:

• Create a function that takes as input a positive integer n and two vectors, x and y of length n, and calculates the proportion of these for which the point (x, y) lies within the unit circle.

• Create a function that takes as input a data table and makes a scatter plot of x and y, coloring the points differently depending on whether they're inside the unit circle or not. You can assume that the data table you are inputting is glyph ready to make this plot.

• Create a function that takes as input a number and multiplies it by 4.

(c) Now use your functions from part (b) to create a function that takes arguments n (for sample size) and plotit (to indicate whether or not to make the plot) and returns the approximated area and optionally makes a plot depending on whether plotit is TRUE or FALSE. Give each argument a default value of your choosing.

(d) The replicate function takes an R expression and evaluates it a specified number of times. You can think of it as a very simplified for loop in which exactly the same code gets evaluated each time through the loop. Use this function to approximate the area of the circle 100 times, first for n=50 and then for n=500 and storing the results in two different vectors.

(e) Make two histograms (facetted by vector size) showing the results from part (c). Add a vertical line to the plot to indicate the true area. Give your plot appropriate axis names and titles and a nice readable theme.

Reference no: EM132118847

Questions Cloud

Project on medical information systems : 300693 WT FINAL PROJECT ASSIGNMENT - you will have to make good use of your CMS using PHP and MySQL for the content delivery
What information do you need to carry out the proposal : You're called in to consult for a company that's issuing about 100 new wireless mobile devices to selected employees.
Overall do you think globalization is positive or negative : Does it increase standards of living around the world, or suffocate other cultures under an onslaught of Big Macs and Coca Cola?
How can quicksort be altered so that it can be applied : How can quicksort be altered so that it can be applied on a doubly-linked list?
Create a function that takes as input a data table : Create a function that takes as input a data table and makes a scatter plot of x and y, coloring the points differently.
Write the r command to produce a table with the same row : Write the R command to produce a table with the same row and column headings, but the entries are the average temperature for that month and year.
Background of management positions chemical : A chemical company is interviewing two people to become its risk manager. One has a background of management positions chemical refineries.
Calculate the average train and test accuracies : Calculate the average train and test accuracies over the 10 runs, and report them.
What are the erm strengths and weaknesses of strategy : In the process, the bank gave enormous trading authority to one ndividual. What are the ERM strengths and weaknesses of this strategy?

Reviews

Write a Review

Computer Engineering Questions & Answers

  Mathematics in computing

Binary search tree, and postorder and preorder traversal Determine the shortest path in Graph

  Ict governance

ICT is defined as the term of Information and communication technologies, it is diverse set of technical tools and resources used by the government agencies to communicate and produce, circulate, store, and manage all information.

  Implementation of memory management

Assignment covers the following eight topics and explore the implementation of memory management, processes and threads.

  Realize business and organizational data storage

Realize business and organizational data storage and fast access times are much more important than they have ever been. Compare and contrast magnetic tapes, magnetic disks, optical discs

  What is the protocol overhead

What are the advantages of using a compiled language over an interpreted one? Under what circumstances would you select to use an interpreted language?

  Implementation of memory management

Paper describes about memory management. How memory is used in executing programs and its critical support for applications.

  Define open and closed loop control systems

Define open and closed loop cotrol systems.Explain difference between time varying and time invariant control system wth suitable example.

  Prepare a proposal to deploy windows server

Prepare a proposal to deploy Windows Server onto an existing network based on the provided scenario.

  Security policy document project

Analyze security requirements and develop a security policy

  Write a procedure that produces independent stack objects

Write a procedure (make-stack) that produces independent stack objects, using a message-passing style, e.g.

  Define a suitable functional unit

Define a suitable functional unit for a comparative study between two different types of paint.

  Calculate yield to maturity and bond prices

Calculate yield to maturity (YTM) and bond prices

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd