Question
MATLAB HELP CODING %% %%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %Before starting this section, make sure you have downloaded 'RandSel.m' %and 'RandLim.m' from Canvas and put them in your
MATLAB HELP CODING
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Before starting this section, make sure you have downloaded 'RandSel.m'
%and 'RandLim.m' from Canvas and put them in your
%current folder and/or add them to your path.
%Here we are going to conduct a Bootstrap analysis to test whether the
%difference in means between two vectors is significant.
%Start by defining two vectors, V1 and V2, as follows:
V1 = [19 6 25 27 29 8 22 13 18 14];
V2 = [18 32 36 14 24 26 19 38];
% Calculate the means of V1 and V2
% Use a 2-sample t-test to determine whether these means of V1 and V2
%are significantly different. Please include both the p-value and the 95%
%confidence interval of the difference between means in your answer.
% Now to begin a Bootstrap analysis, define an empty vector BMD which
%is going to contain a bunch of Bootstrap mean differences
% Make a for-loop that loops 10000 times. In each loop, create a
%Bootstrap sample of V1, a Bootstrap sample of V2, and store the
%difference between the means of the two Bootstrap samples in BMD
%
%Hint: Recall that each Bootstrap sample should have the same number of
%elements as the original sample
% Based on the Bootstrap analysis, is the difference between means
%of V1 and V2 significant? (Hint: find the 95% confidence interval of
%BMD and check if it crosses zero)
% How does your answer to 2.5 compare to your answer to 2.2?
function out = RandLim(n,lower,upper) % returns pseudo-random values drawn from a uniform distribution with lower % and upper limits LOWER and UPPER. % LOWER and UPPER can also be matrices of the same shape as rand(N) would % create % % N is a vector indicating the dimensions of the output: % N = [3] creates a 3x3 matrix % N = [1,3] creates a 1x3 matrix % N = [17,1,3] creates a 17x1x3 matrix % % LOWER and UPPER can be any number
% DN 2008-07-21 Wrote it % DN 2008-09-19 Support for vector lower and upper limits % DN 2016-08-25 Switched from deprecated nargchk to narginchk
narginchk(3,3);
r = rand(n); if (~isscalar(lower) && any(size(lower)~=size(r))) || (~isscalar(upper) && any(size(upper)~=size(r))) error('LOWER and UPPER must each be scalar or have the same shape as rand(N)') else out = lower + r.*(upper-lower); end
function sel = RandSel(in,n) % sel = RandSel(in,n) % if N is a scalar % randomly selects N elements from set IN, elements are replenished. % Output is of size 1xN % if N is a vector % randomly selects prod(N) elements from set IN, with replenishment. N % specifies the shape of the output, e.g., if N=[10 10 5], SEL will be % a 10x10x5 matrix % IN can be of any datatype and can have any number of dimensions and % elements
% DN 2008 wrote it % 2008-08-06 Updated it to support n selections from set (DN) % 2012-06-13 Can now also return shaped inputs through non-scalar n input (DN)
if isscalar(n) n = [1,n]; end
selind = ceil(RandLim(n,0,numel(in))); sel = in(selind);
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started