Logistics模型

一、线性回归

Logistics模型_第1张图片
过程图

%Logistic模型的线性回归
t=[1790 1800 1810 1820 1830 1840 1850 1860 1870 1880 1890 1900 1910 1920 1930 1940 1950 1960]
y=[0.0513 0.0607 0.0726 0.0719 0.0877 0.1081 0.1541 0.1977 0.2568 0.2815 0.3510 0.3965 0.4561 0.5117 0.5614 0.5652 0.5956 0.6305]
x=t-t(1); %将年份转化为时序
plot(x,y,'r.'); %绘制散点图
xlabel('Time');
ylabel('Fercent Urban');
hold on
X=[ones(length(y),1),x']; %自变量矩阵
Y=(log(y.^(-1)-1))'; %因变量矩阵
[B,Bint,E,Eint,Stats]=regress(Y,X); %回归分析
R2=Stats(1);%拟合优度
a=exp(B(1));%模型常数还原
b=-B(2);%回归系数
f=(1+aexp(-bx)).^(-1);%模型表达
plot(x,f,'b-');%添加趋势线
hold on
s=sqrt(sumsqr(y-f)/(length(f)-2));%计算标准误差
a,b,R2,s

二、非线性

function yhat=myfun(beta,x)
b1=beta(1);
b2=beta(2);
yhat=(1+b1exp(b2x)).^(-1);
%以上模型通过编辑窗口保存在Matlab的work文件夹中
t=[1790 1800 1810 1820 1830 1840 1850 1860 1870 1880 1890 1900 1910 1920 1930 1940 1950 1960]
y=[0.0513 0.0607 0.0726 0.0719 0.0877 0.1081 0.1541 0.1977 0.2568 0.2815 0.3510 0.3965 0.4561 0.5117 0.5614 0.5652 0.5956 0.6305]
x=t-t(1); %将年份转化为时序
plot(x,y,'r.'); %绘制散点图
xlabel('Time');
ylabel('Fercent Urban');
hold on
beta0=[1 0];
0=statset('MaxIter',200);
[B,E,J]=nlinfit(x,y,'myfun',beta0,0);
a=B(1);
b=-B(2);
f=(1+aexp(-bx)).^(-1);%模型表达
plot(x,f,'b-');%添加趋势线
hold on
s=sqrt(sumsqr(y-f)/(length(f)-2));%计算标准误差
a,b,s
function yhat=myfun(beta,x)
还没有发现错误的方程

Logistics模型_第2张图片
基于非线性拟合的二参数Logistics模型参数估计过程

好饿呀,想去吃饭啊

你可能感兴趣的:(Logistics模型)