Untitled
unknown
plain_text
a year ago
9.7 kB
4
Indexable
%Spearman's correlation without af n=input("Enter number of observation:"); for i=1:n x(i)=input("Enter X value"); y(i)=input("Enter Y value"); end a1=sort(x); b1=sort(y); e=n; for i=1:n a(i)=a1(e); e=e-1; end e=n; for i=1:n b(i)=b1(e); e=e-1; end j=0; k=0; for i=1:n for j=1:n if x(i)==a(j) rx(i)=j; break; end end for k=1:n if y(i)==b(k) ry(i)=k; break; end end end for i=1:n d(i)=rx(i)-ry(i); dsq(i)=d(i)*d(i); end df=sum(dsq); num=6*df; dino=n*((n*n)-1); ans1=1-(num/dino); disp("Spearman's correlation Rank = "); disp(ans1); with af clear all clc n=input("Enter number of observations:"); for i=1:n x(i)=input("Enter X value"); y(i)=input("Enter Y value"); end rankx=tiedrank(x); ranky=tiedrank(y); for i=1:n c1(i)=1; c2(i)=1; d(i)=rankx(i)-ranky(i); s(i)=d(i)*d(i); end total=sum(s); d=n*(n^2-1); af=0; for i=1:n for j=i+1:n if (x(i)==x(j)) c1(i)=c1(i)+1; end end end for i=1:n if (c1(i)>1) af = af + (c1(i)^3-c1(i))/12; end end for i=1:n for j=i+1:n if (y(i)==y(j)) c2(i)=c2(i)+1; end end end for i=1:n if (c2(i)>1) af= af + ((c2(i)^3)-c2(i))/12; end end a=6*(total+af)/d; spc=1-a; disp(spc); shortcut: x=input('enter value of x'); y=input('enter value of y'); n=length(x); [~,rx]=ismember(x,sort(x,'descend')); [~,ry]=ismember(y,sort(y,'descend')); d=rx-ry; sum1=sum(d.^2); disp('spearmans correlation coefficient:'); r=1-6*sum1/(n*(n^2-1)); disp(r) %Mean of continuous data n=input("Enter the number of classes: "); for i=1:n lower(i)=input("Enter lower class limit: "); upper(i)=input("Enter upper class limit: "); freq(i)=input("Enter frequencies of classes: "); mid(i)=(lower(i)+upper(i))/2; product(i)=mid(i)*freq(i); end disp(lower); disp(upper); disp(freq); total=sum(product); ft=sum(freq); mean=total/ft; disp("Mean = "); disp(mean); %Median of continuous data n=input("Enter the number of classes: "); for i=1:n lower(i)=input("Enter lower class limit: "); upper(i)=input("Enter upper class limit: "); freq(i)=input("Enter frequencies of classes: "); end t=sum(freq)/2; l=0; cf=0; for i=1:n cf=cf+freq(i); if (t<cf) cf=cf-freq(i); median=lower(i)+((t-cf)/freq(i))*k; disp(“Median class is: “); fprintf("%d - %d",lower(i),lower(i+1)); disp("Median is:"); disp(median); break; end end %Mode of continuous data n=input("Enter the number of classes: "); for i=1:n lower(i)=input("Enter lower class limit: "); upper(i)=input("Enter upper class limit: "); freq(i)=input("Enter frequencies of classes: "); end m=max(freq); index=find(freq==m); disp(index); f1=freq(index); disp(f1); f0=freq(index-1); f2=freq(index+1); k=upper(index)-lower(index); l1=f1-f0; l2= 2*f1-f0-f2; l3=l1/l2; disp(“Modal class is: “); fprintf("%d - %d",lower(i),lower(i+1)); mode= lower(index) + k*l3; disp("Mode is: "); disp(mode); %Median of discrete data n=input("Enter the number of elements: "); for i=1:n marks(i)=input("Enter marks of student: "); end for i=1:n for j=1:i if (marks(i)<marks(j)) t=marks(i); marks(i)=marks(j); marks(j)=t; end end end disp(marks); r=rem(n,2); if (r==0) med=(marks(n/2) + marks(n/2+1))/2; end if (r~=0) med=marks((n+1)/2); end disp("Median is: "); disp(med); %Mode of discrete data n=input("Enter the number of elements: "); for i=1:n marks(i)=input("Enter marks of student: "); end max=0; for i=1:n count=0; for j=i+1:n if marks(i)==marks(j) count=count+1; end end if (count>max) max=count; mode=marks(i); end end disp("Mode is: "); disp(mode) %Mean Deviation(discreat) n=input("Enter the number of observations: "); for i=1:n obs(i)=input("Enter values: "); end total=sum(obs); mean=total/n; for i=1:n difference(i)=obs(i)-mean; mls(i)=abs(difference(i)); end total2=sum(mls); md=total2/n; disp("Mean Deviation is: ") disp(md); %Standard Deviation n=input("Enter the number of observations: "); for i=1:n obs(i)=input("Enter values: "); end total=sum(obs); mean=total/n; for i=1:5 k1(i)=obs(i)-mean; k2(i)=k1(i)*k1(i); end t1=sum(k2); var=t1/n; std=power(var,0.5); disp("Varience is: "); disp(var); disp("Standard deviation is: "); disp(std); %Mean Deviation(conitinus) n=input("Enter the number of classes: "); for i=1:n lower(i)=input("Enter lower class limit: "); upper(i)=input("Enter upper class limit: "); freq(i)=input("Enter frequencies of classes: "); mid(i)=(lower(i)+upper(i))/2; product(i)=mid(i)*freq(i); end total=sum(product); ft=sum(freq); mean=total/ft; for i=1:n difference(i)=mid(i)-mean; mls(i)=abs(difference(i)); product2(i)=mls(i)*freq(i); end total2=sum(product2); md=total2/ft; disp("Mean Deviation is: ") disp(md); %Standard Deviation n=input("Enter the number of classes: "); for i=1:n lower(i)=input("Enter lower class limit: "); upper(i)=input("Enter upper class limit: "); freq(i)=input("Enter frequencies of classes: "); mid(i)=(lower(i)+upper(i))/2; product(i)=mid(i)*freq(i); end total=sum(product); ft=sum(freq); mean=total/ft; for i=1:5 k1(i)=freq(i)*mid(i)*mid(i); end t1=sum(k1); l1=t1/ft; var=l1-(mean*mean); std=power(var,0.5); disp("Varience is: "); disp(var); disp("Standard deviation is: "); disp(std); KARL PEARSON CO-EFFICIENT OF CORELATION CALCULATION n=input("Enter number of observation:"); for i=1:n x(i)=input("Enter X value"); y(i)=input("Enter Y value"); xy(i)=x(i)*y(i); sqx(i)=x(i)*x(i); sqy(i)=y(i)*y(i); end sum1=sum(x); sum2=sum(y); sum3=sum(xy); sum4=sum(sqx); sum5=sum(sqy); k1=(n*sum3)-(sum1*sum2); k2=sqrt((n*sum4)-((sum1)^2)); k3=sqrt((n*sum5)-((sum2)^2)); cor=k1/(k2*k3); disp("Co relation coefficient is: "); disp(cor); regression line n=input("enter number of obsarvtion - "); for i=1:n x(i)=input("enter x - "); y(i)=input("enter y - "); xy(i)=x(i)*y(i); x2(i)=x(i)*x(i); end s1=sum(x); s2=sum(y); s3=sum(xy); s4=sum(x2); B=[s2;s3] A=[n s1;s1 s4] c = linsolve(A,B); %disp(c); fprintf("y= %.2f + %.2fx\n",c(1),c(2)); regression curve clc clear all % quadratic curve fitting n=input("enter number of observation - "); for i=1:n x(i)=input("enter x"); y(i)=input("enter y"); xy(i)=x(i)*y(i); x2(i)=x(i)*x(i); x2y(i)=x2(i)*y(i); x3(i)=x2(i)*x(i); x4(i)=x3(i)*x(i); end s1=sum(x); s2=sum(y); s3=sum(xy); s4=sum(x2); s5=sum(x2y); s6=sum(x3); s7=sum(x4); D=[s2;s3;s5]; E=[n s1 s4;s1 s4 s6;s4 s6 s7]; F=linsolve(E,D); fprintf("y= %.2f + %.2fx + %.2fx2\n",F(1),F(2),F(3)); y=ae^bx clc clear all % quadratic curve fitting n=input("enter number of observation - "); for i=1:n x(i)=input("enter x"); y(i)=input("enter y"); lny(i)=log(y(i)); xy(i)=x(i)*lny(i); x2(i)=x(i)*x(i); end s1=sum(x); s2=sum(y); s3=sum(xy); s4=sum(lny); s5=sum(x2); A=[n s1;s1 s5]; B=[s4;s3]; c=linsolve(A,B); fprintf("y= %.2f e^%.2f * x2",exp(c(1)),c(2)); y=ab^x clc clear all % quadratic curve fitting n=input("enter number of observation - "); for i=1:n x(i)=input("enter x"); y(i)=input("enter y"); lny(i)=log(y(i)); xy(i)=x(i)*lny(i); x2(i)=x(i)*x(i); end s1=sum(x); s2=sum(y); s3=sum(xy); s4=sum(lny); s5=sum(x2); A=[n s1;s1 s5]; B=[s4;s3]; c=linsolve(A,B); fprintf("y= %.2f* %.2f^x",exp(c(1)),exp(c(2))); Regression clc clear all % regression n=input("enter number of observation - "); for i=1:n x(i)=input("enter x - "); y(i)=input("enter y - "); xy(i)=x(i)*y(i); x2(i)=(x(i)*x(i)); y2(i)=(y(i)*y(i)); end x2=sum(x2) y2=sum(y2) xy=sum(xy) x=sum(x) y=sum(y) meanx=x/n meany=y/n bxy=(n*xy-(x*y))/(n*y2-(y*y)); byx=(n*xy-(x*y))/(n*x2-(x*x)); disp("Regression X On Y - "); fprintf("(x- %.2f) = %.2f (y-%.2f)\n",meanx,bxy,meany); fprintf("x = %dy + %d\n",bxy,(meanx-(meany*bxy))); disp("Regression Y On X - "); fprintf("(y- %.2f) = %.2f (x - %.2f)\n",meany,byx,meanx); fprintf("y = %dx + %d",byx,(meany-(meanx*byx))); %Binomial Distribution n=input("Enter the total number of trails: "); r=input("Enter the number of successful trails out of n: "); p=input("Enter probability of success: "); q=1-p; factn=factorial(n); factr=factorial(r); factnr=factorial(n-r); ncr=factn/(factr*factnr); ps=ncr*(p^r)*(q^(n-r)); disp("Probability of success is: "); disp(ps); %Poison Distribution clear all clc n=input("Enter the total number of trails: "); p=input("Enter probability of success: "); x=input("Enter the number of success: "); lambda=n*p; k=0-lambda; p1=exp(k)*(lambda^x)/factorial(x); p2=0; for i=1:x-1 p2=p2+(exp(k)*(lambda^i)/factorial(i)); end p3=1-p2-p1; fprintf("P(t=x)=%d\n",(p1)); fprintf("P(0<t<x)=%d\n",(p2)); fprintf("P(t>x)=%d",(p3)); %Line Graph x=[0 1 2 3 4 5 6 7 8 9 10]; y=[0 1 4 9 16 25 36 49 64 81 100]; z=[0 1 8 27 64 125 216 343 512 729 1000]; hold on; plot(x,y,'-s'); title("x vs y"); xlabel('x'); ylabel('y'); xlim([0,10]); ylim([0,100]); plot(x,z,'-.'); title("x vs z"); xlabel('x'); ylabel('z'); xlim([0,10]); ylim([0,1000]); hold off; %hold off; %grid on; %Pie Graph a=[20;30;40;30]; pie(a); title("Pie Chart"); %Bar Graph b=[126;94;162;57]; barh(b); title("Bar Graph"); ylabel("Number of Observation"); xlabel("Value"); %BoxPlot c=[184;152;160;143;168;170]; figure boxplot(c) title("Box Plot Graph");