N(100,5)N(115,15)

Then run the simulation 1,000 times and compute how many times the null hypothesis was rejected the end of 1,000 times because that each sample sizes scanning native 2 to 50.

You are watching: Matlab t-test

Finally, I need to plot the result of the rejections of H0 versus the sample size.

h = zeros(1000,1);k = 0;for i = 1:1000 r1 = (); r2 = (); because that j= 2:50 r1(j-1)=normrnd(100,5,<1,j>); r2(j-1)=normrnd(110,15,<1,j>); end h(i)=ttest2(r1,r2) if h(i)==1 k=k+1; finish percent_of_rejection_Null=(k/1000*100);end%plot(h vs sample_size)Could somebody help me to exactly the above code?


*

*

There to be a few issues through your code:

ri is a vector of changing size therefore you should append it to a struct that deserve to store elements with different sizes -> cell array.percent_of_rejection_Null demands to be a vector to keep all the values.you didn"t point out what form of plot girlfriend are looking for specifically, I proved the bar plot but it"s simple to readjust to the preferred one friend need.the calculation of h was problematic, its a vector that 50 every iteration therefore need to calculate the sum of 1.

The item of code is:

h = zeros(1000,1);percent_of_rejection_Null = zeros(1000,1);k = 0;for i = 1:1000 r1 = ; r2 = ; for j= 2:50 r1j-1=normrnd(100,5,<1,j>); r2j-1=normrnd(110,15,<1,j>); finish h = cellfun(
ttest2, r1, r2); k = sum(h==1); percent_of_rejection_Null(i) = (k/1000*100);endfigure;plot(percent_of_rejection_Null)The result plot is:

*

If the output isn"t what you to be after, please modify your question in order for me to adjust.


*

Thanks for contributing solution to stack Overflow!

Please be sure to answer the question. Carry out details and share your research!

But avoid

Asking for help, clarification, or responding to various other answers.Making statements based on opinion; earlier them increase with references or personal experience.

See more: Happy Labor Day Images 2017, Labor Day Parade Stock Photos And Images

To discover more, check out our tips on writing good answers.


write-up Your price Discard

By clicking “Post her Answer”, you agree come our terms of service, privacy policy and cookie plan


Not the answer you're looking for? Browse various other questions tagged matlab t-test or ask your very own question.


*

site style / logo © 2021 stack Exchange Inc; user contributions licensed under cc by-sa. Rev2021.9.14.40215


Stack Overflow works finest with JavaScript allowed
*

your privacy

By click “Accept every cookies”, friend agree stack Exchange have the right to store cookie on your device and disclose details in accordance through our Cookie Policy.