Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %Kamil Sosna
- %Task 1
- d = matfile('d14.mat');
- x_vect = d(:,1);
- y_vect = d(:,2);
- mean_x = mean(x_vect);
- mean_y = mean(y_vect);
- r_value = 0;
- std_x = std(x_vect);
- std_y = std(y_vect);
- for i = 1:15
- r_value = r_value + (x_vect(i)-mean_x)*(y_vect(i)-mean_y);
- end
- r_value = r_value/(std_x*std_y*(14));
- disp(r_value)
- %concludions : stample is corelated with nither strong nor weak
- %correlation for growing trend
- X = ((length(x_vect)-2)/1-r_value*r_value);
- value = r_value*(sqrt(X));
- disp(value)
- tinv(0.025, length(x_vect)-1)
- b_1 = ((r_value*std_y)/std_x) ;
- b0 = mean_y- mean_x*b_1;
- disp(b_1); % a coeff
- disp(b0); % intercept
- value_of_regression_model = b_1* 58 + b0;
- disp(value_of_regression_model) %value for x=48
- residuals = zeros(length(x_vect),1);
- for i = 1:length(x_vect)
- residuals(i) = y_vect(i) - (b0+(b_1*x_vect(i)));
- end
- %y_val = zeros(500);
- %x_val2 = zeros(500);
- iterator2 = 1;
- x_val=[40:0.1:90];
- %for x_val = 40:0.1:90
- % x_val2(iterator2) = x_val;
- % y_val(iterator2) = b_1*x_val2(iterator2) + b0;
- %iterator2 = iterator2 + 1;
- %end
- y_val = b_1*x_val+b0;
- scatter(x_vect,y_vect)
- hold on
- scatter(x_val,y_val)
- %plotmatrix(x_vect,residuals)
- %////////////////////////////////////////////////////////////////
- %Task 2
- X=d7(:,1);
- Y=d7(:,2);
- plotmatrix(X,Y);
- %Yes, we can see there will be linear relation between points.
- %using power_transform
- YY = power_transform(Y,0);
- Y12 = power_transform(Y, 1/2);
- YYY = power_transform(Y,1);
- Y2 = power_transform(Y,2);
- Y3=power_transform(Y,3);
- Y5= power_transform(Y,5);
- Y10=power_transform(Y,10);
- %diplaying figures
- plotmatrix(X,Y);
- figure;
- plotmatrix(X,YY);
- figure;
- plotmatrix(X,Y12);
- figure;
- plotmatrix(X,YYY);
- figure;
- plotmatrix(X,Y2);
- figure;
- plotmatrix(X,Y5);
- figure;
- plotmatrix(X,Y10);
- figure;
- plotmatrix(X,Y3);
- %Calculating correlation coefficient
- R=corrcoef(X,Y);
- R0=corrcoef(X,YY);
- R12=corrcoef(X,Y12);
- R1=corrcoef(X,YYY);
- R2=corrcoef(X,Y2);
- R3=corrcoef(X,Y3);
- R5=corrcoef(X,Y5);
- R10=corrcoef(X,Y10);
- %For us the best parameter p would be 3, because its sample correlation
- %coefficient is equal to 0.9077. If its closer to 1 or -1, its better.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement