matlab 中的相关性检验,MatlabR2012a空间面板空间自相关性检验

clear all;

%sp.mat 中数据已取对数

format long

format compact

load sp.mat;

% dimensions of the problem

T=13; % number of time periods

N=29; % number of regions

% row-normalize W

W=normw(w1); % function of LeSage

y=sp(:,[1]); % column number in the data matrix that corresponds to the dependent variable

x=sp(:,[2:8]); % column numbers in the data matrix that correspond to the independent variables

xconstant=ones(N*T,1);

[nobs K]=size(x);

% ----------------------------------------------------------------------------------------

% ols estimation(一般面板模型)

results=ols(y,[xconstant x]);

vnames=char('EF','C','UR','TR','DA','PCG','RD','OD','GOV');

prt_reg(results,vnames,1);

sige=results.sige*((nobs-K)/nobs);

loglikols=-nobs/2*log(2*pi*sige)-1/(2*sige)*results.resid'*results.resid

LMsarsem_panel(results,W,y,[xconstant x]); % (Robust) LM tests

%moran 检验

I=eye(T);W1=kron(I,W);

res=moran(y,[xconstant x],W1);

prt(res);

% ----------------------------------------------------------------------------------------

% spatial fixed effects + (robust) LM tests for spatial lag and spatial error model(空间固定效应模型)

% fixed effects, within estimator

% demeaning of the y and x variables

model=1;

[ywith,xwith,meanny,meannx,~,meantx]=demean(y,x,N,T,model);

results=ols(ywith,xwith);

vnames=char('EF','UR','TR','DA','PCG','RD','OD','GOV'); % should be changed if x is changed

prt_reg(results,vnames);

FE=meanny-meannx*results.beta; % including the constant term

yme = y - mean(y);

ee=ones(T,1);

error=y-kron(ee,FE)-x*results.beta;

rsqr1 = error'*error;

rsqr2 = yme'*yme;

FE_rsqr2 = 1.0 - rsqr1/rsqr

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值