function bb = stretchbetaval(mn,sd,minb,maxb,fx) % STBetaval(mean, sd, minb, maxb, fx) % This routine generates a stretched beta number with % mean mn, standard deviation sd, minimum and maximum % values (minb, maxb) and CDF value fx % this function calls the function betaval.m if sd == 0; bb = mn; % with no variation, then the value = mean else % convert the stretched beta parameters to corresponding % ones for a {0,1} beta mnbeta = (mn - minb)/(maxb-minb); sdbeta = sd/(maxb-minb); % next, check for undoable parameter combos if sdbeta < (mnbeta*(1-mnbeta))^0.5 bvalue = betaval(mnbeta,sdbeta,fx); % find beta value bb=bvalue*(maxb-minb) +minb; % convert to stretched value else disp('the sd is too high for the mean'); disp('for a vital rate with the following') disp('mean, sd, and min and max values') disp([mn,sd,minb,maxb]) disp('the maximum sd possible is:') maxsd = ((mnbeta*(1-mnbeta))^0.5)*(maxb-minb); disp(maxsd); disp('you should abort the program (control C)') disp('and reset the limits or the sd of this rate'); pause; bb=NaN; end; % else end; % else