求教OLS Matlab程序,看不懂,运行不出来.clear;clc;load('data');n=size(X,1);k=size(X,2);X=[ones(n,1) X(:,1:2)];beta_hat=(X'*X)\(X'*y);y_hat=X*beta_hat;e_hat=y-y_hat;var_hat=(e_hat'*e_hat)/n;P=X*inv(X'*X)*X';h=diag(diag(P));e_bar=(1-diag(h)).^
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/17 00:16:56
求教OLS Matlab程序,看不懂,运行不出来.clear;clc;load('data');n=size(X,1);k=size(X,2);X=[ones(n,1) X(:,1:2)];beta_hat=(X'*X)\(X'*y);y_hat=X*beta_hat;e_hat=y-y_hat;var_hat=(e_hat'*e_hat)/n;P=X*inv(X'*X)*X';h=diag(diag(P));e_bar=(1-diag(h)).^
求教OLS Matlab程序,看不懂,运行不出来.
clear;
clc;
load('data');
n=size(X,1);
k=size(X,2);
X=[ones(n,1) X(:,1:2)];
beta_hat=(X'*X)\(X'*y);
y_hat=X*beta_hat;
e_hat=y-y_hat;
var_hat=(e_hat'*e_hat)/n;
P=X*inv(X'*X)*X';
h=diag(diag(P));
e_bar=(1-diag(h)).^(-1/2).*e_hat;
var_bar=sum(e_bar.^2)/n;
s_square=sum(e_hat.^2)/(n-k);
e_twitter=e_hat./(1-diag(h));
var_twitter=sum(e_twitter.^2)/n;
V0_hat=inv(1/n*(X'*X))./s_square;
V_twitter=n*inv(X'*X)*(X'*D_twitter*X)*inv(X'*X);
var_y_hat=var(y);
var_y_twitter=var(y)*n/(n-1);
R_square=1-var_hat/var_y_hat;
R__bar_square=1-s_square/var_y_twitter;
R_twitter_square=1-var_twitter/var_y_hat;
save('results');
求教OLS Matlab程序,看不懂,运行不出来.clear;clc;load('data');n=size(X,1);k=size(X,2);X=[ones(n,1) X(:,1:2)];beta_hat=(X'*X)\(X'*y);y_hat=X*beta_hat;e_hat=y-y_hat;var_hat=(e_hat'*e_hat)/n;P=X*inv(X'*X)*X';h=diag(diag(P));e_bar=(1-diag(h)).^
很复杂啊,给你改了下,看看吧.
clear;
clc;
load('data');
n=size(X,1);
k=size(X,2);
X=[ones(n,1) X(:,1:2)];
beta_hat=(X'*X)\(X'*y);
y_hat=X*beta_hat;
e_hat=y-y_hat;
var_hat=(e_hat'*e_hat)/n;
P=X*inv(X'*X)*X';
h=diag(diag(P));
e_bar=(1-diag(h)).^(-1/2).*e_hat;
var_bar=sum(e_bar.^2)/n;
s_square=sum(e_hat.^2)/(n-k);
e_twitter=e_hat./(1-diag(h));
var_twitter=sum(e_twitter.^2)/n;
V0_hat=inv(1/n*(X'*X))./s_square;
D_hat=diag(e_hat.^2);
D_bar=diag(e_bar.^2);
D_twitter=diag(e_twitter.^2);
V_hat=n*inv(X'*X)*(X'*D_hat*X)*inv(X'*X);
V_bar=n*inv(X'*X)*(X'*D_bar*X)*inv(X'*X);
V_twitter=n*inv(X'*X)*(X'*D_twitter*X)*inv(X'*X);
var_y_hat=var(y);
var_y_twitter=var(y)*n/(n-1);
R_square=1-var_hat/var_y_hat;
R__bar_square=1-s_square/var_y_twitter;
R_twitter_square=1-var_twitter/var_y_hat;
save('results');