Question

R2. The goal in this problem is to create something called a P-P plot (youll need the result from R1 at a key place). Heres the idea: We start by choosing (say) 100 values for q evenly spaced between 0 and 10 (qvals). We also generate (say) 100000 random numbers from what R claims is an exponential distribution with (say) λ-1/2. Using a for loop, for each value of q, we calculate what percentage of numbers from the exponential distribution we expect to be less than q (see R1), and also, what percentage of numbers from our list of 100000 that actually are less than q. After doing all this, we plot the 100 expected percentages against the 100 actual percentages Think about what graph we should get before you complete the code and then run the below code. Include a rough sketch of your plot and explain why it is shaped the way it is. 1 set.seed (3.1415) # bring our random nesses into alignment # how many values for q 3 ngs 4 lambda = 1/2 6 expectedpercentages - 7 actualpercentages 8 nnums - 9 nums # use seq function to help you # set up vector for expected values # set up vector for actual values # how many random numbers to create # make the random nums 10 11 for i in 1:nqs) 12 expectedpercentages[i]- 13 actualpercentagesi] 14 15 16 plot

0 0
Add a comment Improve this question Transcribed image text
Answer #1

If the actual percentages match the theoretical percentages , the points in a PP Plot plot would fall on a 45 line.

Here we have drawn a sample from what R claims to be an exponential distribution, and comparing it against actual exponential distribution. Hence the actual percentages should closely match with that of the theoretical/expected percentages and the points would be around 45 line.

If x has exponential distribution with parameter lambda=rac{1}{2} , the cdf of X is

P(X<x)=F(x)=1-e^{lambda x}=1-e^{-rac{x}{2}}

The theoretical percentage of numbers from exponential distribution we expect to be less than q is

Expected Percentages = P(X < g) x 100 = (1-e-2) × 100

Following is the R code (all statements starting with # are comments)

#set the random seed set.seed (3.1415) #set number of values for q nqs<-100 # 3et the parameter for exponential di 3 tribution lambda<-1/2 #gene rate nqs values of q equally spaced between 0 and 10 qva13(-seq (from=0, to-10, length. out=nq3 ) #set up the vector of expected values expectedpercentages<-numeric (nqs) #set up the vector of actual values actualpercentages<-numeric (nqS) #set the number of random numbers to create nnurns<-100000 #generate nnums random numbers from exponential distribution nums<-rexp (nnums, lambda) #find the percentages for each value in qvals for (i in 1:nqs) i #find the pr (Kqva13[1]) * 100 expectedpercentages [1] <-(1-exp (-qvals [1] /2) ) *100 #actual percentage, count the number from exponential actualpercentages [1](-sum (nums<=qvals [1] ) /nnums * 100 distribution less than qva13[1] plot (actualpercentages, expectedpercentages, xlab= Actual abline (0,1, col=red) Percentages, ylab=Expected Percentages,main=P-P plott

output is

P-P plot 100 80 40 60 20 Actual Percentages

We can say that the numbers generated from what R claims to be exponential, are indeed exponential as the points lie on a 45 line

Add a comment
Know the answer?
Add Answer to:
R2. The goal in this problem is to create something called a P-P plot (you'll need...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • R2. Let X ~ N(μ 10.82). Following up on R1, we will be approximating μ2, which...

    R2. Let X ~ N(μ 10.82). Following up on R1, we will be approximating μ2, which we can see should be 100, For now, let the sample size be n = 3, Pick 3 random numbers from X, compute X., and repeat the process a total of 50000 times. Plot a smooth version of the histogram of these 50000 values for X: the plot(density(.. command in R wll be useful. Now find the average of your 50000 values and make...

  • Solve d,e and f please using R code Part I: qqplots This part deals with qqplots...

    Solve d,e and f please using R code Part I: qqplots This part deals with qqplots of all kinds. Let's do some easy expe riments, first. Let's take a sample from a normal distribution with mu-2, sigma 3, and then look at the hist and the qqplot of that data: set.seed(3) n 100 # Sample size x norm(n,2,3) # Sample from N(mu-2, sigma-3) hist(x) # Looks normal. But that depends on breaks. qqnorm(x) # This doesn't depend on binsize, and...

  • R2 IS THE QUESTION,THANKS! R2. Let X ~ N(μ = 10.82). Following upon we be approximating...

    R2 IS THE QUESTION,THANKS! R2. Let X ~ N(μ = 10.82). Following upon we be approximating μwe can see should be 100. For now, let the sample size be n = 3, Pick 3 random numbers from X, compute X', and repeat the process a total of 50000 times. Plot a smooth version of the histogram of these 50000 values for X: the plot(density(...)) command in R will be useful. Now find the average of your 50000 values and make...

  • please do this problem in matlab and show me the code. Thanks. please do this problem...

    please do this problem in matlab and show me the code. Thanks. please do this problem in matlab and show me the code. Thanks. please do this problem in matlab and show me the code. Thanks. please do this problem in matlab and show me the code. Thanks. please do this problem in matlab and show me the code. Thanks.please do this problem in matlab and show me the code. Thanks. please do this problem in matlab and show me...

  • please do this problem in matlab and show me the code. Thanks. please do this problem...

    please do this problem in matlab and show me the code. Thanks. please do this problem in Matlab and show me the code. Thanks. Problem #1: Circuits and linear-systems In the last HW you developed the governing equations for the “Wheatstone”-bridge circuit used extensively in engineering applications (shown below). B R R2 A D G m RA с E The resulting equations were solved for the output voltage and currents using the function: function [V_out, I_vector] =Wheatstone_bridge (v_in, R_vector) In...

  • Problem 3 (13 pts): (modified from Attaway Problem 3.39) a) (5 pts) Using the Matlab rand () func...

    Problem 3 (13 pts): (modified from Attaway Problem 3.39) a) (5 pts) Using the Matlab rand () function, create a script that generates a row vector (1 row X 20 columns) of random numbers, each with magnitude between 0 and 5 b) (3 pts) Use the round() function to turn all of the values into whole numbers by rounding down (truncate the decimal part on your vector) c) (5 pts) Add code to your script to generate a new vector...

  • Use the attached Matlab code as a basis to solve the following ordinary differential equation usi...

    Question 1 QUESTION 2 Use the attached Matlab code as a basis to solve the following ordinary differential equation using Euler's method, with timestep of 0.1, from t-0to t-100. d)0) -0 - sin (5vt cos(у Plot y versus t from t=0 to t=100. How many local maxima are on this interval(do not include end points). Be careful to count them all! Answer should be an integer 1 w% Matlab code for the solution of Module 2 3 dt-9.1; %dt is...

  • Thanks ahead of time!!! Problem 2: Modeling inseet population dynamies The use of arrays and matrix...

    Thanks ahead of time!!! Problem 2: Modeling inseet population dynamies The use of arrays and matrix algebra are ideal for modeling population dynamics of organisms. If n) is computed from represents the number of organisms at time t, then the number at a later time, t+1, can be n(t+1) An(t). The array (vector, n) consists of the nurnber of females in each age class, and the array (matrix, A), called a Leslie matrix, is the survival- replacement matrix. Multiplying the...

  • Hello I need help with this program. Should programmed in C! Program 2: Sorting with Pointers...

    Hello I need help with this program. Should programmed in C! Program 2: Sorting with Pointers Sometimes we're given an array of data that we need to be able to view in sorted order while leaving the original order unchanged. In such cases we could sort the data set, but then we would lose the information contained in the original order. We need a better solution. One solution might be to create a duplicate of the data set, perhaps make...

  • I only need help with the discussion there are many info that you do not need put I put just in ...

    I only need help with the discussion there are many info that you do not need put I put just in case as well as my data table. please do it as soon as u can Meauements ODeit1 Check2 Meaurements Checi3 Ced Check5 Check6 Measurements Check7 heck8 4058 33 536 1502 1035 979 119478 041 1.0319|0.554972| 64261| 153|15542033681 995781 5266566 1578807 298h 1631 119 1209430016 079096812 0.418135246 0,00032665 011890:004668155728441 0293237 1.291809502 1.22833 1.28 1952 -1116 4281 140616885511984206317 3346 8162 0.78...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT