楼主: ywh19860616
26303 92

[问答] 怎么把这个矩阵保存到excel中 [推广有奖]

21
ywh19860616 发表于 2012-10-24 20:32:30 |只看作者 |坛友微信交流群
zhangtao 发表于 2012-10-24 20:01
To get started, select MATLAB Help or Demos from the Help menu.
??? Error using ==> wk1read
Fi ...
zhangzhao兄,你的数据是放在E:\lotus\cigarette.wk1吗?
应该不是命令错误,只是提示找不到数据文件,自己设置过
路径就行了。
一份耕耘,一份收获。

使用道具

22
zhangtao 发表于 2012-10-24 20:34:07 |只看作者 |坛友微信交流群
% PURPOSE: An example of two types of sampling for rho in the semip_g function
% Gibbs sampling spatial Probit model with individual effects
% using 1996 presidential election data set
%               
%---------------------------------------------------
% USAGE: semip_gd2
%---------------------------------------------------

clear all;
load semip.mat;

vnames = strvcat('y','highs','college','grad','non-white', ...
'income','urban');

% x-matrix contains 3,110 x 6 matrix with:
%   col1 = high school graduates as a percent of population     
%   col2 = college percent  
%   col3 = graduate school
%   col4 = non-white
%   col5 = median income     
%   col6 = urban  

% z = 0,1 with 0 = Dole wins, 1 = Clinton wins, 3,110 counties
% W = a 48x48 spatial weight matrix (standardized)
% nregions = 48
% regionobs = a 48 x 1 vector with the # of counties in each state
% states organized alphabetically

[n k] = size(x);


ndraw = 2500;
nomit = 500;
prior.rval = 4;
prior.dflag = 1; % metropolis-hastings for rho
prior.rmin = 0;
prior.rmax = 1;

% use M-H sampling for rho
result = semip_g(z,x,W,nregions,regionobs,ndraw,nomit,prior);
prt(result,vnames);

prior.dflag = 0; % use alternative approach to sample for rho

result2 = semip_g(z,x,W,nregions,regionobs,ndraw,nomit,prior);
prt(result2,vnames);

[h1,f1,y1] = pltdens(result.pdraw);
[h2,f2,y2] = pltdens(result2.pdraw);

plot(y1,f1,'.',y1,f2,'o');
legend('Met-H','Inversion');
在以上程序中pltdens和legend这两个函数哪儿?为什么在原函数包中看不到?
数学好就是要天天学

使用道具

23
ywh19860616 发表于 2012-10-24 20:36:10 |只看作者 |坛友微信交流群
epoh 发表于 2012-10-24 14:46
帮你看了,似乎Paul Elhorst的网站也没提供DEMO数据
ttp://www.regroningen.nl/elhorst/software.shtml  ...
epoh老师,我还想请教您一下,winbugs提示这个错误
sorry something wrong in procedure Stack.Value in module Graphstack
通常是因为数据量太大吗? 程序赋初始值后,把迭代次数放大,也会出现
这个错误。
一份耕耘,一份收获。

使用道具

24
ywh19860616 发表于 2012-10-24 20:40:11 |只看作者 |坛友微信交流群
zhangtao 发表于 2012-10-24 20:34
% PURPOSE: An example of two types of sampling for rho in the semip_g function
% Gibbs sampling spa ...
lenged是matlab自带的命令,就是给图形注释标签。

%%%%%  plotdens
function [h,f,xx] = plotdens(x,h,positive,kernel)
% PURPOSE: Draw a nonparametric density estimate.
%---------------------------------------------------
% USAGE: [h f y] = pltdens(x,h,p,kernel)
%        or pltdens(x) which uses gaussian kernel default
% where:
%        x is a vector
%        h is the kernel bandwidth
%          default=1.06 * std(x) * n^(-1/5); Silverman page 45
%        p is 1 if the density is 0 for negative values
%        k is the kernel type:
%          =1 Gaussian (default)
%        =2 Epanechnikov
%        =3 Biweight
%        =4 Triangular
%   A jittered plot of the
%   observations is shown below the density.
%---------------------------------------------------
% RETURNS:
%        h = the interval used
%        f = the density
%        y = the domain of support
%        plot(y,f) will produce a plot of the density
% --------------------------------------------------
% SEE ALSO hist, histo
%---------------------------------------------------

%       Anders Holtsberg, 18-11-93
%       Copyright (c) Anders Holtsberg

x = x(:); n = length(x);
if nargin < 4, kernel = 1; end
if nargin < 3, positive = 0; end
if nargin < 2, h = []; end
if isempty(h)
   h = 1.06 * std(x) * n^(-1/5);  % Silverman page 45
end
if positive & any(x < 0)
   error('There is a negative element in X')
end
mn1 = min(x); mx1 = max(x);
mn = mn1 - (mx1-mn1)/3;
mx = mx1 + (mx1-mn1)/3;
gridsize = 256;
xx = linspace(mn,mx,gridsize)';
d = xx(2) - xx(1);
xh = zeros(size(xx));
xa = (x-mn)/(mx-mn)*gridsize;
for i=1:n
   il = floor(xa(i));
   a  = xa(i) - il;
   xh(il+[1 2]) = xh(il+[1 2])+[1-a, a]';
end
xk = [-gridsize:gridsize-1]'*d;
if kernel == 1
   K = exp(-0.5*(xk/h).^2);
elseif kernel == 2
   K = max(0,1-(xk/h).^2/5);
elseif kernel == 3
   c = sqrt(1/7);
   K = (1-(xk/h*c).^2).^2 .* ((1-abs(xk/h*c)) > 0);
elseif kernel == 4
   c = sqrt(1/6);
   K = max(0,1-abs(xk/h*c));
end
K = K / (sum(K)*d*n);
f = ifft(fft(fftshift(K)).*fft([xh ;zeros(size(xh))]));
f = real(f(1:gridsize));
if positive
   m = sum(xx<0);
   f(m+(1:m)) = f(m+(1:m)) + f(m:-1:1);
   f(1:m) = zeros(size(f(1:m)));
   xx(m+[0 1]) = [0 0];
end
if nargout == 0
plot(xx,f)
if ~ishold
   hold on
   d = diff(get(get(gcf,'CurrentAxes'),'Ylim'))/100;
   plot(x,(-rand(size(x))*6-1)*d,'.')
   plot([mn mx],[0 0])
   axis([mn mx -0.2*max(f) max(f)*1.2])
   hold off
end
end;

已有 2 人评分学术水平 热心指数 信用等级 收起 理由
epoh + 5 + 5 + 5 热心帮助其他会员
zhangtao + 5 + 5 + 5 好的意见建议

总评分: 学术水平 + 10  热心指数 + 10  信用等级 + 10   查看全部评分

一份耕耘,一份收获。

使用道具

25
zhangtao 发表于 2012-10-24 21:03:50 |只看作者 |坛友微信交流群
ywh19860616 发表于 2012-10-24 20:40
lenged是matlab自带的命令,就是给图形注释标签。

%%%%%  plotdens
ywh19860616学兄,那这个plotdens是哪儿的函数?
非常感谢!
数学好就是要天天学

使用道具

26
ywh19860616 发表于 2012-10-24 21:18:44 |只看作者 |坛友微信交流群
zhangtao 发表于 2012-10-24 21:03
ywh19860616学兄,那这个plotdens是哪儿的函数?
非常感谢!
http://rgm2.lab.nig.ac.jp/RGM2/f ... Smodelling:plotDens
上面链接有比较详细的介绍。
如果你的电脑上没有这个函数,那就把这个函数下载保存到你电脑上,
应该就可以用了。
一份耕耘,一份收获。

使用道具

27
epoh 发表于 2012-10-24 21:20:05 |只看作者 |坛友微信交流群
zhangtao 发表于 2012-10-24 20:01
To get started, select MATLAB Help or Demos from the Help menu.
??? Error using ==> wk1read
Fi ...
1.cigardemo.wk1,Spat-Sym-US.wk1两个文件都在
   jplv7\spatial\panel
  所以可以读到

2.cigarette.wk1,你只要放在jplv7\spatial\panel,就可读到

3.pltdens.m 在
   jplv7\graphs
  Elhorst JP (2011) MATLAB Software for Spatial Panels
  很多都要用到 LeSage's Spatial Econometrics Toolbox
已有 1 人评分学术水平 热心指数 信用等级 收起 理由
zhangtao + 5 + 5 + 5 好的意见建议

总评分: 学术水平 + 5  热心指数 + 5  信用等级 + 5   查看全部评分

使用道具

28
epoh 发表于 2012-10-24 21:21:16 |只看作者 |坛友微信交流群
ywh19860616 发表于 2012-10-24 20:36
epoh老师,我还想请教您一下,winbugs提示这个错误
sorry something wrong in procedure Stack.Value in ...
老兄这个问题,你可参考
  https://www.jiscmail.ac.uk/cgi-bin/webadmin?A2=bugs;f81d94fc.1205
我不清楚程序,数据,不便回答
已有 1 人评分学术水平 热心指数 信用等级 收起 理由
ywh19860616 + 5 + 5 + 5 好的,哈哈,谢谢epoh老师

总评分: 学术水平 + 5  热心指数 + 5  信用等级 + 5   查看全部评分

使用道具

29
ywh19860616 发表于 2012-10-24 21:26:34 |只看作者 |坛友微信交流群
epoh 发表于 2012-10-24 21:21
老兄这个问题,你可参考
  https://www.jiscmail.ac.uk/cgi-bin/webadmin?A2=bugs;f81d94fc.1205
我不清 ...
好的,我看下您给的链接,谢谢epoh老师。
一份耕耘,一份收获。

使用道具

30
zhangtao 发表于 2012-10-24 21:37:01 |只看作者 |坛友微信交流群
epoh 发表于 2012-10-24 21:20
1.cigardemo.wk1,Spat-Sym-US.wk1两个文件都在
   jplv7\spatial\panel
  所以可以读到
??? Error using ==> wk1read
Too many output arguments.

Error in ==> demoLMsarsem_panel at 1
A=wk1read('E:\lotus\cigarette.wk1',1,0); % data set with T=30

>>
现在又出现以上问题,epoh都是,您看如何解决?
数学好就是要天天学

使用道具

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-5-1 10:03