Basically, give the MATLAB code for what is done in the picture. Vector = [2410
ID: 3552611 • Letter: B
Question
Basically, give the MATLAB code for what is done in the picture.
Vector = [2410 2240 2445 2296 2667 2139 2639 2456 2594 2295 2573 2457 2430 2416 2549 2233 2642 2735 2840 2720 2893 2804 2698 2426 2581 2573 2478 2408 2665 2337 2102 2315 2276 2278 2390 2152 2404 2214 2194 1783 1637 1458 1384 1367 1229 1222 1008 1188 1213 1365 1233 969 956 869 802 538 663 696 446 336 396 304 230 184 186 214 314 405 299 308 246 223 348 287 211 283 258 275 348 327 342 300 271 327 295 338 294 302 352 368 439 399 374 507 428 358 292 283 349 344 365 448 595 804 665 488 409 399 416 544 583 638 625 552 491 540 506 476 452 389 453];
Explanation / Answer
function [param,stat]=sigm_fit(alpha,beta,pmax,pmin,k)
alpha=alpha(:);
beta=beta(:);
if nargin<=1 %fail
fprintf('');
help sigm_fit
return
end
a_pmin=[quantile(beta,0.05) quantile(beta,0.95) NaN 1];
if sum(beta==quantile(beta,0.5))==0
temp=alpha(beta==quantile(beta(2:end),0.5));
else
temp=alpha(beta==quantile(beta,0.5));
end
a_pmin(3)=temp(1);
if nargin==2 %simplest valid input
pmax=NaN(1,4);
pmin=a_pmin;
k=1;
end
if nargin==3
pmin=a_pmin;
k=1;
end
if nargin==4
k=1;
end
if exist('fixed_params','var')
if isempty(pmax)
pmax=NaN(1,4);
end
end
if exist('initial_params','var')
if isempty(pmin)
pmin=a_pmin;
end
end
if exist('plot_flag','var')
if isempty(k)
k=1;
end
end
f_str='f = @(param,xval)';
free_param_count=0;
bool_vec=NaN(1,4);
for i=1:4;
if isnan(pmax(i))
free_param_count=free_param_count+1;
f_str=[f_str ' param(' num2str(free_param_count) ')'];
bool_vec(i)=1;
else
f_str=[f_str ' ' num2str(pmax(i))];
bool_vec(i)=0;
end
if i==1; f_str=[f_str ' + (']; end
if i==2;
if isnan(pmax(1))
f_str=[f_str '-param(1) )./ ( 1 + 10.^( ('];
else
f_str=[f_str '-' num2str(pmax(1)) ')./ (1 + 10.^(('];
end
end
if i==3; f_str=[f_str ' - xval ) *']; end
if i==4; f_str=[f_str ' ) );']; end
end
eval(f_str)
[BETA,RESID,J,COVB,MSE] = nlinfit(alpha,beta,f,pmin(bool_vec==1));
stat.param=BETA';
% confidence interval of the parameters
stat.paramCI = nlparci(BETA,RESID,'Jacobian',J);
% confidence interval of the estimation
[stat.ypred,delta] = nlpredci(f,alpha,BETA,RESID,'Covar',COVB);
stat.ypredlowerCI = stat.ypred - delta;
stat.ypredupperCI = stat.ypred + delta;
free_param_count=0;
for i=1:4;
if isnan(pmax(i))
free_param_count=free_param_count+1;
param(i)=BETA(free_param_count);
else
param(i)=pmax(i);
end
end
if k==1
x_vector=min(alpha):diff(minmax(alpha'))/100:max(alpha);
plot(alpha,beta,'k.',x_vector,f(param,x_vector),'r-')
xlim(minmax(x_vector))
end
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.