代写NE/PS 212: Exam 2 Extra Credit Question代写留学生Matlab语言

- 首页 >> C/C++编程

NE/PS 212:  Exam 2 Extra Credit Question

1    Extra Credit Question

For exam 2, here is the extra credit question.  It is worth 6 points.

Please write a function that performs two sample t-tests with unequal variances.  The inputs to the function should be the following.

1.  X: the rst vector of numbers

2.  Y: the second vector of numbers

3.  type: equal variances or unequal variances.  You can use numeric values for type (say 1 for pooled and 2 for unpooled).

The function must return the t-statistic, the degrees of freedom and the  p-value for the test.   The function must also print out whether you reject the null hypothesis that the means are equal.  Please  name the function newttest and provide appropriate comments.  Here is a skeleton of my function

f u n c t i o n    [ tS t at  ,   pValue  ,   DF ]   =   n ewt t e st ( X , Y , v a r ty p e )

%  T h is   f u n c t i o n    p e rfo r m s   a   u n p a i r e d   two   sa m p le   t-t e s t

%   I t   can   pe rfo r m   both   poo le d   and   u n poo l ed   t-t e s t s .

%

%

%  more   comments   h e r e    . .

%  CC ,   BU ,   2020

i f   v a r ty p e==1

%  Pe rfo r m i ng   a   poo led   v a r i a n c e   t-t e s t

e l s e

%  Pe rfo r m i ng   an   u n poo led   v a r i a n c e   t-t e s t

end

Please test your code with the following data generated using these commands

rng(’default’);

X  =  3  +  4*randn(1,20);

Y  =  6  +  7*randn(1,30);

Run your code with X and Y as defined above and also make sure you check them with the inbuilt MATLAB functions for t-tests.

[h,p,ci,st]  =  ttest2(X,Y,'vartype','unequal')

[h,p,ci,st]  =  ttest2(X,Y,'vartype','equal')

1.1    Expected Results

●  For the unpooled case, I get the DF to be 46.0894, the p-value to be 0.7696, and my t-value to be -0.2946.

●  For the pooled case, I get the DF to be 48, the p-value to be 0.7789, and my t-statistic to be -0.2823. Here are the equations for the t-statistic for equal and unequal variances:

1.2    Pooled Variance

The pooled variance/standard deviation case assumes that the true standard deviation of both groups is the same, and that we can use both sample standard deviations together to get a better estimate of that true standard deviation.

The degrees of freedom in this case are n1 + n2 - 2

1.3    Unpooled Variance

Assumption that the underlying variance for both groups is the same is not applicable in many settings.  The equation for the t-statistic with Unpooled variance is given by the following equation

The Null hypothesis is μ 1 = μ2, so this reduces to

The degrees of freedom for this case is


 


站长地图