Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %% QUESTION 1 - Regression for No' of Parasites for an Area Unit & the Static Index (0 static index = fastes blood flow)
- % x - Parasite Index, Inepended Variable
- % Y - Static Index, Depended Variable
- x = [ 0;1;2;3;4;5;6;7;13;18;21;24;27 ]; % Parasite Index
- Y = [ 0;4.41;10.13;15.67;19.15;23.74;28.33;30.45;59.17;81.63;106.98;110.36;145.74 ]; % Static Index
- T = table(Y,x); % putting Data in a Table
- N = length(T.x);
- Mx = mean(T.x);
- X = [ ones(N,1) T.x ]; % building the X Matrix With ones & x
- %% Paragraph A
- b = inv(X'*X)*X'*Y; % calculating the Regression Parameters b0 & b1
- Yhat = X*b; % building Y-Hat - Means Line
- Syx = sqrt ( sum((Y-Yhat).^2) / (N-2) );
- SE_Yhat = Syx .* sqrt((1/N)*ones(N,1)+(T.x-Mx).^2 ./ ((N-1)*var(T.x)));
- t_Yhat = Yhat / SE_Yhat; % acquiring t-Distribution for Y-hat to build it's Confidence Interval
- CI_Yhat = [Yhat Yhat] + SE_Yhat * tinv([0.025 0.975],N-2) ; % Calculating Confidence Intervals for Y-hat
- Sb0 = Syx * sqrt( (1/N) + (Mx.^2) / ((N-1)*(var(T.x).^2)) );
- Sb1 = Syx / sqrt( (N-1) * var(T.x) );
- tb0 = b(1)/Sb0; % acquiring t-Distribution for b0 to build it's Confidence Interval
- tb1 = b(2)/Sb1; % acquiring t-Distribution for b1 to build it's Confidence Interval
- CI_b0 = b(1) + Sb0 * tinv([0.025 0.975],N-2); % Calculating Confidence Intervals for b0
- CI_b1 = b(2) + Sb1 * tinv([0.025 0.975],N-2); % Calculating Confidence Intervals for b1
- % Drawing the Parameters, Means Line & their Confidence Interval
- [sort_x,sort_Ind]=sort(T.x); % sorting X & it's Indexes for the Plots
- figure
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement