Advertisement
Guest User

Untitled

a guest
May 26th, 2015
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. %% QUESTION 1 - Regression for No' of Parasites for an Area Unit & the Static Index (0 static index = fastes blood flow)
  2. % x - Parasite Index, Inepended Variable
  3. % Y - Static Index, Depended Variable
  4. x = [ 0;1;2;3;4;5;6;7;13;18;21;24;27 ]; % Parasite Index
  5. 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
  6. T = table(Y,x); % putting Data in a Table
  7. N = length(T.x);
  8. Mx = mean(T.x);
  9. X = [ ones(N,1) T.x ]; % building the X Matrix With ones & x
  10.  
  11. %% Paragraph A
  12. b = inv(X'*X)*X'*Y; % calculating the Regression Parameters b0 & b1
  13. Yhat = X*b; % building Y-Hat - Means Line
  14. Syx = sqrt ( sum((Y-Yhat).^2) / (N-2) );
  15. SE_Yhat = Syx .* sqrt((1/N)*ones(N,1)+(T.x-Mx).^2 ./ ((N-1)*var(T.x)));
  16. t_Yhat = Yhat / SE_Yhat; % acquiring t-Distribution for Y-hat to build it's Confidence Interval
  17. CI_Yhat = [Yhat Yhat] + SE_Yhat * tinv([0.025 0.975],N-2) ; % Calculating Confidence Intervals for Y-hat
  18. Sb0 = Syx * sqrt( (1/N) + (Mx.^2) / ((N-1)*(var(T.x).^2)) );
  19. Sb1 = Syx / sqrt( (N-1) * var(T.x) );
  20. tb0 = b(1)/Sb0; % acquiring t-Distribution for b0 to build it's Confidence Interval
  21. tb1 = b(2)/Sb1; % acquiring t-Distribution for b1 to build it's Confidence Interval
  22. CI_b0 = b(1) + Sb0 * tinv([0.025 0.975],N-2); % Calculating Confidence Intervals for b0
  23. CI_b1 = b(2) + Sb1 * tinv([0.025 0.975],N-2); % Calculating Confidence Intervals for b1
  24. % Drawing the Parameters, Means Line & their Confidence Interval
  25. [sort_x,sort_Ind]=sort(T.x); % sorting X & it's Indexes for the Plots
  26. figure
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement