联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-23:00
  • 微信:codinghelp

您当前位置:首页 >> Algorithm 算法作业Algorithm 算法作业

日期:2019-12-08 07:32

Assignment 3

Question 1

Write a function that takes two matrices (say, A and B) as arguments and return the

matrix multiplication of A and B. Recall that in matrix multiplication, let C = A × B, then

Cij =P

k AikBkj . Notice that in matrix multiplication, the number of columns in A must

be the same as the number of rows in B. So in your program, if the inputs do not satisfy

the condition, then provide an error message. Notice that, you are not allowed to use the

R internal matrix multiplication function for this question, although you can verify your

solution with it.

Question 2

Suppose we had forgotten the formula for computing the area of a circle. All is not

lost. We can easily use the computer to approximate a circles area by simulation. For

convenience, we want to determine the area of the unit circle with radius 1 and name this

unknown 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 square

completely 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 random

point Z is determined by two coordinates, say X and Y , which have independent uniform

distributions on the interval [?1, 1]. The probability of Z being inside the circle is given by

the 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 probability

for Z being inside the circle by 4. Whats left is to generate a large number of random points

Z, calculate the proportion of points inside the circle, and multiply this by 4. This is our

estimate 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 away

is 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 is

defined by its origin and the radius, the distance from the circles origin to the point is given.

Question 3

In statistical hypothesis testing, you specify a hypothesis about a population parameter

(your null hypothesis, or H0). You then draw a sample from this population and calculate

a statistic that’s used to make inferences about the population parameter. Assuming that

1

the null hypothesis is true, you calculate the probability of obtaining the observed sample

statistic or more extreme results. If the probability is sufficiently small, you reject the null

hypothesis 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 made

a correct decision. The power of a test is defined by the probability of rejecting the null

hypothesis 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 null

hypothesis 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 want

to 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. We

know that if we set the significance level to α (usually 1% or 5%) , the test will reject the

null hypothesis α% of the time (for a large number of samples), although the data actually

come from a normal distribution with mean 0 and variance 1 (the chance of making a type I

error is α% ). Show this by generating 1000 samples of size 100, calculating for each sample

whether or not the null hypothesis is rejected and summarizing how often the null hypothesis

was rejected (even when it is true). Recall that the criterion for rejecting the null hypothesis

in this case is that you reject the null hypothesis if

xˉ ? μ0σ/√n> z1?α.

Question 4

This 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 the

population corresponding to the alternative hypothesis.

? Estimate the power of your test in Q3 by generating 1000 samples of size 10000 of the

population corresponding to the alternative hypothesis.

2


版权所有:留学生编程辅导网 2020 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp