Create a function that takes in x

Assignment Help Basic Computer Science
Reference no: EM13765589

Problem 1

The goal of this simulation problem is to examine how accurate the normal approximation to binomial is without the continuity correction.

Create a function that takes in x (the number of successes we are interested in), n the total sample size, p the proportion of successes, and Which Way which will take on characters "<", ">","<=",">=". This function should perform the following steps:

Step i. Find the exact probability we are interested in using the built in R function pbinom (see handout for details). Notice you should have an if else chain which calculates the probability based on Which Way. Call this value True Prob.

Step ii. Inside the if else chain, you should also calculate the normal approximation to binomial for the value of x. Do not implement the continuity correction. Call this value Approx Prob.

Step iii. Your function should output the difference between the exact probability and the approximate probability. Then, use your function to calculate the absolute value of the difference between the exact and approximate probability for the following probabilities and parameters:

(a) P(X < 7) for n = 15, p = 0.40
(b) P(X ≥ 5) for n = 30, p = 0.20
(c) P(X ≤ 10) for n = 50, p = 0.25
(d) P(X > 50) for n = 200, p = 0.10

Problem 2

The goal of this simulation problem is to examine how accurate the normal approximation to binomial is with the continuity correction.
Create a function that takes in x (the number of successes we are interested in), n the total sample size, p the proportion of successes, and Which Way which will take on characters "<", ">","<=",">=".
Notice that you should be able to modify your previous function (give it a new name though), and this time implement the continuity correction. Then, use your function to calculate the absolute value of the difference between the exact and approximate probability for the following probabilities and parameters:
(a) P(X < 7) for n = 15, p = 0.40
(b) P(X ≥ 5) for n = 30, p = 0.20
(c) P(X ≤ 10) for n = 50, p = 0.25
(d) P(X > 50) for n = 200, p = 0.10

Problem 3

This problem will use your functions from Problem 1 and Problem 2 to see how the approximations perform when n increases. Your function should take in a vector of sample sizes all.n, the probability of success p, and Which Way which will take on characters "<", ">","<=",">=".

Create a function that calculates the following binomial probability:
P(X ≤ (n/2)) and returns a matrix of all. n rows, and two columns; the first column being the difference between the actual probability and the normal approximation to binomial without the continuity correction for all values in all. n, and the second being the difference between the actual probability and the normal approximation to binomial with the continuity correction for all values in all. n.

Hint: sapply will automatically create a matrix if you return two values in your sapply loop. If it is the reverse of what you want, you can use X = t(X) to flip the matrix.

Then, use your function to do the following:

(a) For all.n = seq(10,400,2), p = 0.50, and the appropriate value of WhichWay, use your function to get back a large matrix of the differences. Do not print out this matrix!. Find the mean of each column and report the two means.

(b) Then, create a histogram of the differences between the actual and approximate probabilities for each method (with and without continuity). Report these two histograms (make sure you label them!).

(c) Also create two separate line plots where the values of all.n are on the x-axis, and the difference between the actual and approximate probabilities are on the y-axis. Report the two line graphs (make sure you label them!) Notice the default axis limits.

(d) Do you think the continuity correction is worth implementing? I.e, if you were approximating a binomial probability with a normal distribution, would you use the continuity correction? You can use parts (a), (b) and (c) to support your answer.

Reference no: EM13765589

Questions Cloud

Describing your personal criminological theory : Write a 700- to 1,050-word paper describing your personal criminological theory. Address the following in your paper: How would you explain the occurrence of crime and why people commit crime
Estimate the quantity of connectivity routers-switches : Your organization opened seven new branch offices in five states. Each branch office has five floors. All the branch offices use the same Internet domain name. The organization has approximately 25 servers and anticipates that an additional 30 ser..
Product using the production method : Assuming Sunny Day accounts for the by product using the production method, what is the inventoriable cost for each product and Sunny Day's gross margin?
Explain why many children growing up in poor families : explain why many children growing up in poor families succeed in school and in life citing your Learning Resources for this week to validate your thinking and ideas.
Create a function that takes in x : Create a function that takes in x (the number of successes we are interested in), n the total sample size, p the proportion of successes, and Which Way which will take on characters " "," =". This function should perform the following steps:
Identification and analysis and effective decision-making : Considering the context as described above, how do organizations - in terms of culture, structure, and traditional ways of doing things (processes), impact both risk identification and analysis (RIA) and effective decision-making
Managing health care quality issue : Write clearly and concisely about health care management using proper writing mechanics.
Identify the philosophical basis for each theory : Write a 1,050- to 1,750-word paper in which you evaluate your selected criminological theory. Identify the philosophical basis for each theory
Define the accounting equation : Define the accounting equation. Define, explain, and example the following: Asset, Liability, Equity, Revenue, and Expense.

Reviews

Write a Review

 

Basic Computer Science Questions & Answers

  Perform the physical design

Perform the physical design and implementation using SQL Data Definition Language

  Find the type of language of the below languages

Find the type of language of the below languages L1 = {0^i1^j|i!=j}; L2 = {0^i1^j|i=j},L3={0^i1^j|i=2j+1},L4={0^i1^j|i!=2j}

  Ordering a burrito at a fast food mexican restaurant

Draw an activity diagram for ordering a burrito at a fast food mexican restaurant (e.g. Chipotle or Qdoba)

  Write a machine-language program to input two one-digit num

Write a machine-language program to input two one-digit numbers, add them, and output the one-digit sum. Write it in a format suitable for the loader and execute it on the Pep/8 simulator.

  Consider a demand-paging system

Consider a demand-paging system with the following time-measured utilizations.

  A company called fastcabs provides a taxi service to clients

Identify the functional dependencies that exist between the columns of the table in Figure 14.21 and identify the primary key and any alternate key(s) (if present) for the table.

  Consider a scenario where the contingency planning

consider a scenario where the contingency planning management team cpmt of your organization has designated you as the

  Question in unix os

What if we need the portion from a text based on some keyword. Now i want the middle portion where i found EO427849242. I tried with sed but it does not give me the desired result.

  A graph is two-connected iff

A graph is two-connected iff, removal of any single vertex and the edges adjacent to that vertex, leaves the graph connected. How can we tell if a graph is two-connected? Explain your algorithm in English

  Write a program that asks user to input grade of student

Write a program that asks the user to input the grade of the student. If the grade is equal or greater than 60, the program prints the word "pass", otherwise it prints the word "fail".

  Discuss reasons unix® internet commands remained mostly same

Discuss some of the reasons UNIX® Internet commands have remained mostly the same since the creation of the Internet

  Eu directive on the protection of personal data

How does the EU directive on the protection of personal data impose requirements on organizations in non-EU countries?"

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