Assignment 3Question 1Write a function that takes two matrices (say, A and B) as arguments and return thematrix multiplication of A and B. Recall that in matrix multiplication, let C = A × B, thenCij =Pk AikBkj . Notice that in matrix multiplication, the number of columns in A mustbe the same as the number of rows in B. So in your program, if the inputs do not satisfythe condition, then provide an error message. Notice that, you are not allowed to use theR internal matrix multiplication function for this question, although you can verify yoursolution with it.Question 2Suppose we had forgotten the formula for computing the area of a circle. All is notlost. We can easily use the computer to approximate a circles area by simulation. Forconvenience, we want to determine the area of the unit circle with radius 1 and name thisunknown constant π. We know that the area covered by a square with the corner points(−1, 1), (1, 1), (1, −1), and (−1, −1) equals 4, as the length of each side is 2. This squarecompletely contains the unit circle. If we had a random point somewhere in the square,we could calculate the probability that the point is also inside the unit circle. A randompoint Z is determined by two coordinates, say X and Y , which have independent uniformdistributions on the interval [−1, 1]. The probability of Z being inside the circle is given bythe ratio of the circles area and the squares area or, more mathematically:P(Z is inside the circle) = (circle area)/(square area) = π/4.Knowing this, we can estimate (the unknown) π by multiplying the estimated probabilityfor Z being inside the circle by 4. Whats left is to generate a large number of random pointsZ, calculate the proportion of points inside the circle, and multiply this by 4. This is ourestimate of π. Write a R program for this problem and estimate pi with 100, 1000, and 10,000 random points. Try to work with complete vectors only and avoid loops. How far awayis the approximation from the pi we (fortunately) happen to know?Hint: You need to know how to check if a point (x, y) is inside the circle. As the circle isdefined by its origin and the radius, the distance from the circles origin to the point is given.Question 3In statistical hypothesis testing, you specify a hypothe代写program留学生作业、R编程设计作业调试、R语言作业代做、代写program课程作业 帮做C/C++编程|帮做Hsis about a population parameter(your null hypothesis, or H0). You then draw a sample from this population and calculatea statistic that’s used to make inferences about the population parameter. Assuming that1the null hypothesis is true, you calculate the probability of obtaining the observed samplestatistic or more extreme results. If the probability is sufficiently small, you reject the nullhypothesis in favor of its opposite (referred to as the alternative or research hypothesis, H1).If the null hypothesis is false and the statistical test leads us to reject it, you’ve madea correct decision. The power of a test is defined by the probability of rejecting the nullhypothesis given that the alternative hypothesis is correct.If the null hypothesis is true and you don’t reject it, again you’ve made a correct decision.If the null hypothesis is true but you reject it, youve committed a Type I error. If the nullhypothesis is false and you fail to reject it, youve committed a Type II error.In this problem, we will use simulation to examine a statistical hypothesis test. We wantto test the null hypothesis that the population of mean of a normally distributed sample isµ0 = 0, with known variance 1. Let the alternative be that the mean is equal to µ1 = 1. Weknow that if we set the significance level to α (usually 1% or 5%) , the test will reject thenull hypothesis α% of the time (for a large number of samples), although the data actuallycome from a normal distribution with mean 0 and variance 1 (the chance of making a type Ierror is α% ). Show this by generating 1000 samples of size 100, calculating for each samplewhether or not the null hypothesis is rejected and summarizing how often the null hypothesiswas rejected (even when it is true). Recall that the criterion for rejecting the null hypothesisin this case is that you reject the null hypothesis ifx¯ − µ0σ/√n> z1−α.Question 4This question is a continuation of Q3, in which we examine the power of the test.• Estimate the power of your test in Q3 by generating 1000 samples of size 10 of thepopulation corresponding to the alternative hypothesis.• Estimate the power of your test in Q3 by generating 1000 samples of size 10000 of thepopulation corresponding to the alternative hypothesis.2转自:http://www.daixie0.com/contents/18/4443.html
网友评论