全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 R语言论坛
2012-10-24 22:24:34
zhangtao 发表于 2012-10-24 21:37
??? Error using ==> wk1read
Too many output arguments.
没问题的.
%%%
A=wk1read('cigarette.wk1',1,0);
A  <1380x6 double>
  0        1        4.54223038621422        -0.0675932911325282        -0.159064694629687        3.93035366037472
  0        2        4.82831373730230        -0.247121550020870        -0.206132205487673        4.15188616271897
  .....
%%%%
>> demoLMsarsem_panel

Ordinary Least-squares Estimates
Dependent Variable =        logcit   
R-squared      =    0.3209
Rbar-squared   =    0.3199
sigma^2        =    0.0343
Durbin-Watson  =    1.6311
Nobs, Nvars    =   1380,     3
***************************************************************
Variable       Coefficient      t-statistic    t-probability
intercept         3.485067        30.752482         0.000000
logp             -0.859023       -25.162254         0.000000
logy              0.267733        10.848028         0.000000


loglikols =

  370.3279

LM test no spatial lag, probability          =   66.4657,    0.000
robust LM test no spatial lag, probability   =   58.2636,    0.000
LM test no spatial error, probability        =  153.0401,    0.000
robust LM test no spatial error, probability =  144.8380,    0.000
LM lag test for omitted spatial lag in panel data
                     
LM value                  66.46567338
Marginal Probability       0.00000000
chi(1) .01 value           6.64000000

LM error test for spatial errors in panel data
                     
LM value                 153.04007124
Marginal Probability       0.00000000
chi(1) .01 value           6.64000000

Robust LM lag test for omitted spatial lag in panel data
                     
LM value                  58.26362253
Marginal Probability       0.00000000
chi(1) .01 value           6.64000000

Robust LM error test for spatial errors in panel data
                     
LM value                 144.83802039
Marginal Probability       0.00000000
chi(1) .01 value           6.64000000


Ordinary Least-squares Estimates
Dependent Variable =           logcit
R-squared      =    0.5446
Rbar-squared   =    0.5443
sigma^2        =    0.0074
Durbin-Watson  =    1.5471
Nobs, Nvars    =   1380,     2
***************************************************************
Variable      Coefficient      t-statistic    t-probability
logp            -0.702293       -38.875780         0.000000
logy            -0.010556        -0.657335         0.511075


FE_rsqr2 =

    0.8528


logliksfe =

  1.4252e+003

LM test no spatial lag, probability          =  136.4292,    0.000
robust LM test no spatial lag, probability   =   29.5127,    0.000
LM test no spatial error, probability        =  255.7150,    0.000
robust LM test no spatial error, probability =  148.7985,    0.000
LM lag test for omitted spatial lag in panel data
                     
LM value                 136.42922576
Marginal Probability       0.00000000
chi(1) .01 value           6.64000000

LM error test for spatial errors in panel data
                     
LM value                 255.71499922
Marginal Probability       0.00000000
chi(1) .01 value           6.64000000

Robust LM lag test for omitted spatial lag in panel data
                     
LM value                  29.51270710
Marginal Probability       0.00000006
chi(1) .01 value           6.64000000

Robust LM error test for spatial errors in panel data
                     
LM value                 148.79848056
Marginal Probability       0.00000000
chi(1) .01 value           6.64000000


Ordinary Least-squares Estimates
Dependent Variable =           logcit
R-squared      =    0.3410
Rbar-squared   =    0.3406
sigma^2        =    0.0283
Durbin-Watson  =    1.9980
Nobs, Nvars    =   1380,     2
***************************************************************
Variable      Coefficient      t-statistic    t-probability
logp            -1.205073       -22.660295         0.000000
logy             0.565364        18.664801         0.000000


FE_rsqr2 =

    0.4404


logliktfe =

  503.8506

LM test no spatial lag, probability          =   44.0402,    0.000
robust LM test no spatial lag, probability   =    0.3302,    0.566
LM test no spatial error, probability        =   62.8646,    0.000
robust LM test no spatial error, probability =   19.1546,    0.000
LM lag test for omitted spatial lag in panel data
                     
LM value                  44.04022085
Marginal Probability       0.00000000
chi(1) .01 value           6.64000000

LM error test for spatial errors in panel data
                     
LM value                  62.86462230
Marginal Probability       0.00000000
chi(1) .01 value           6.64000000

Robust LM lag test for omitted spatial lag in panel data
                     
LM value                   0.33024003
Marginal Probability       0.56551778
chi(1) .01 value           6.64000000

Robust LM error test for spatial errors in panel data
                     
LM value                  19.15464149
Marginal Probability       0.00001205
chi(1) .01 value           6.64000000


Ordinary Least-squares Estimates
Dependent Variable =           logcit
R-squared      =    0.3944
Rbar-squared   =    0.3940
sigma^2        =    0.0053
Durbin-Watson  =    1.7791
Nobs, Nvars    =   1380,     2
***************************************************************
Variable      Coefficient      t-statistic    t-probability
logp            -1.034884       -25.632843         0.000000
logy             0.528543        11.668292         0.000000


FE_rsqr2 =

    0.8955


loglikstfe =

  1.6617e+003

LM test no spatial lag, probability          =   46.9005,    0.000
robust LM test no spatial lag, probability   =    1.1563,    0.282
LM test no spatial error, probability        =   54.6548,    0.000
robust LM test no spatial error, probability =    8.9106,    0.003
LM lag test for omitted spatial lag in panel data
                     
LM value                  46.90051952
Marginal Probability       0.00000000
chi(1) .01 value           6.64000000

LM error test for spatial errors in panel data
                     
LM value                  54.65480685
Marginal Probability       0.00000000
chi(1) .01 value           6.64000000

Robust LM lag test for omitted spatial lag in panel data
                     
LM value                   1.15633190
Marginal Probability       0.28222757
chi(1) .01 value           6.64000000

Robust LM error test for spatial errors in panel data
                     
LM value                   8.91061923
Marginal Probability       0.00283517
chi(1) .01 value           6.64000000

LR-test joint significance spatial fixed effects, degrees of freedom and probability = 2315.7004,    46,   0.0000
LR-test joint significance time-periode fixed effects, degrees of freedom and probability =  473.0957,    30,   0.0000
>>
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2012-10-25 08:55:31
epoh老师,您好!
wk1read.m这个文件在jplv7的那个文件夹中?
winbugs14在win7(64位)如何安装?
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2012-10-25 09:38:04
zhangtao 发表于 2012-10-25 08:55
epoh老师,您好!
wk1read.m这个文件在jplv7的那个文件夹中?
winbugs14在win7(64位)如何安装?
C:\MATLAB7\toolbox\matlab\iofun\wk1read.m
matlab自带的函数。
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2012-10-25 09:43:40
zhangtao 发表于 2012-10-25 08:55
epoh老师,您好!
wk1read.m这个文件在jplv7的那个文件夹中?
winbugs14在win7(64位)如何安装?
WinBUGS安装在win7(64位)请参考底下官网:
If installing on a 64-bit machine, you should download a zipped version of
the whole file structure and unzip it into Program Files or wherever you want it.
  http://www.mrc-bsu.cam.ac.uk/bugs/winbugs/contents.shtml
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2012-10-25 21:54:13
Doc2.doc
大小:(253 KB)

 马上下载


为什么不显示stats和density等呢?

无标题.png
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2012-11-6 08:44:13
epoh 发表于 2012-10-25 09:43
WinBUGS安装在win7(64位)请参考底下官网:
If installing on a 64-bit machine, you should download a  ...
epoh老师,这个是我对应的数据,谢谢您。
gdp.rar
大小:(13.59 KB)

 马上下载

本附件包括:

  • gdp.csv


二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2012-11-6 12:18:51
ywh19860616 发表于 2012-11-6 08:44
epoh老师,这个是我对应的数据,谢谢您。
x11,x12,x33,x35含缺失值
我改为0后,结果如下:
         Generalized Linear Models Fitted via Gradient Boosting

Call:
glmboost.formula(formula = form1, data = data2, control = control1)


         Squared Error (Regression)

Loss function: (y - f)^2


Number of boosting iterations: mstop = 1000
Step size:  0.1
Offset:  0.01817126

Coefficients:
  (Intercept)            x1            x3            x4            x5
4.988252e-02 -1.783758e-05 -3.325863e-04  1.731596e-03  1.182520e-02
           x6            x7            x8            x9           x10
-1.940684e-03 -6.002514e-03 -2.681798e-03  3.762021e-02  7.426345e-06
          x11           x12           x13           x14           x15
2.259706e-06  2.531580e-07  2.386428e-03  1.071192e-02 -3.181342e-04
          x16           x18           x20           x21           x22
-5.284128e-04 -1.671078e-03 -6.686344e-03  1.234232e-01 -6.203724e-02
          x23           x24           x25           x26           x27
-2.756625e-02 -9.297037e-04 -1.406581e-02 -2.184697e-02  1.934449e-03
          x28           x29           x33           x34           x36
2.575692e-03 -7.811003e-05  2.853482e-04  2.063190e-04 -3.549440e-03
          x37           x38           x41           x42           x43
3.869174e-02  4.379488e-03  3.387566e-04  7.391188e-04  6.550135e-03
          x44           x46           x47           x49           x51
1.780142e-02  6.158870e-08 -4.528557e-04  1.719498e-08 -3.591763e-04
          x53           x54           x55           x56           x58
-3.543192e-05 -7.124848e-03 -5.904705e-04 -2.342254e-03  2.939947e-03
          x59           x62           x63           x66           x67
-4.617615e-03 -4.090289e-03 -4.379344e-03  7.329981e-03 -3.673455e-04
attr(,"offset")
[1] 0.01817126
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2012-11-6 14:16:07
epoh 发表于 2012-11-6 12:18
x11,x12,x33,x35含缺失值
我改为0后,结果如下:
         Generalized Linear Models Fitted via Gradie ...
谢谢epoh老师,的确是因为缺省值引起的。
原以为是我数据框用错了。
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2012-11-6 14:26:51
ywh19860616 发表于 2012-11-6 14:16
谢谢epoh老师,的确是因为缺省值引起的。
原以为是我数据框用错了。
有缺省值,就会形成Levels

> data2$x10
[1]  220.5315   49.4502 1178.2328    8.7110   87.8611  406.1147  345.6478
[8]   38.4017   41.3377  530.1852   28.4091   33.5902   68.3077   34.8851
[15]   92.7045  109.5385   26.6591 1034.5308   38.3881  418.3289   21.5287
[22]    8.9971   60.4110   70.1908   88.1299   35.9247   36.8064   30.4252
[29]  148.0764  236.6730  101.4822  514.8791   41.3107   14.9737    8.0623
[36]   27.3537    7.2393   57.8243    6.6483   51.8819   64.8345    6.0854
[43]   50.6950  132.7459  316.3302  116.4905   98.3452   65.1672   62.7328
[50]  223.9572  128.8893   68.8771  117.5753    0.3220    6.7214   18.8325
[57]    9.7540    4.0014   52.4661    3.9487   40.3624   14.5470   15.4315
[64]   10.8185    0.3733    6.5355   40.2938    2.9893   19.3578   11.7381
[71]    3.5857    9.2622   68.7562   12.0414    6.3008   15.4798  569.6023
[78]    5.8578    2.9547   85.6828   10.4181   16.3993   55.0294   27.9774
[85]    4.6132  741.0994  235.8646
> data2$x11
[1] 74.74003 99.27784 0        0        19.58585 0        12.39925 64.09662
[9] 18.25667 3.438613 63.06274 77.20781 13.07549 0        14.02777 8.653484
[17] 0        2.801948 51.21938 0        132.9795 0        47.15005 30.37214
[25] 25.41653 74.31586 51.07906 0        30.75152 0        0        13.4373
[33] 29.02468 78.66887 145.0772 72.5593  150.3266 21.19768 162.5115 17.43064
[41] 17.50638 174.6589 71.91255 12.4985  0        36.76809 9.127183 30.34203
[49] 30.30622 0        28.76789 35.73729 29.15127 3729.293 238.6484 76.17235
[57] 131.6355 272.176  21.18003 310.6865 32.95543 0        67.62395 107.5375
[65] 3081.967 171.5903 62.65871 391.4445 86.4634  66.78308 420.7111 112.1376
[73] 33.61261 88.70178 120.6083 69.06823 .        169.9543 353.6062 22.41369
[81] 141.8488 98.96389 43.88341 56.84623 199.0842 6.251487 4.690946
75 Levels: . 0 107.5375 112.1376 12.39925 12.4985 120.6083 ... 99.27784
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2012-11-6 14:32:48
epoh 发表于 2012-11-6 14:26
有缺省值,就会形成Levels

> data2$x10
是的,这个问题困扰了好多天。
非常感谢epoh老师。
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2012-11-6 21:15:33
epoh 发表于 2012-11-6 14:26
有缺省值,就会形成Levels

> data2$x10
splm_1.0-00.zip
大小:(145.31 KB)

 马上下载


epoh老师,您好!
     这个splm包中的数据Produc,可以通过fix(Produc)看到,
您看有没有什么办法可以把Produc下载下来,然后保存为
excel格式,以供练习之用。
非常感谢!
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2012-11-6 21:52:45
zhangtao 发表于 2012-11-6 21:15
epoh老师,您好!
     这个splm包中的数据Produc,可以通过fix(Produc)看到,
您看有没有什么办法可以 ...
data(Produc)
write.csv(Produc,"Produc.csv")
Produc.csv
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2012-11-7 08:54:47
epoh 发表于 2012-11-6 21:52
data(Produc)
write.csv(Produc,"Produc.csv")
Produc.csv
载入需要的程辑包:lmtest
载入需要的程辑包:Ecdat
警告信息:
1: 程辑包‘splm’是用R版本2.15.2 来建造的
2: 程辑包‘spam’是用R版本2.15.2 来建造的
3: 程辑包‘ibdreg’是用R版本2.15.2 来建造的
4: 程辑包‘car’是用R版本2.15.2 来建造的
5: 程辑包‘lmtest’是用R版本2.15.2 来建造的
> data(Produc)
>  write.csv(Produc,"Produc.csv")
>  Produc.csv
错误: 找不到对象'Produc.csv'
> fix(Produc)
>
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2012-11-7 11:03:59
zhangtao 发表于 2012-11-7 08:54
载入需要的程辑包:lmtest
载入需要的程辑包:Ecdat
警告信息:
哈哈!Produc.csv是我要上传的文件
只是昨日上传失败
####
data(Produc)
write.csv(Produc,"Produc.csv")
以上两句已经把数据写入Produc.csv
要读出只要
Produc=read.csv("Produc.csv")
Produc
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2012-11-8 08:23:36
epoh 发表于 2012-11-7 11:03
哈哈!Produc.csv是我要上传的文件
只是昨日上传失败
####
example.rar
大小:(28.17 KB)

 马上下载


Sexample=read.csv("D:\Backup\Documents\example\Sexample.csv")

Uexample=read.csv("D:\Backup\Documents\example\Uexample.csv")

data(Sexample, package = "Ecdat")data(Uexample)fm <- log(gsp) ~ log(pcap) + log(pc) + log(emp) + unemp## the two standard specifications (SEM and SAR) one with FE## and the other with RE:## fixed effects panel with spatial errorsfespaterr <- spml(fm, data = Sexample, listw = mat2listw(Uexample), model="within", spatial.error="b")summary(fespaterr)## random effects panel with spatial lagrespatlag <- spml(fm, data = Sexample, listw = mat2listw(Uexample), model="random", spatial.error="none", lag=TRUE)summary(respatlag) epoh老师,您好!  根据已经传给您的splm包,运行以上程序,出现以下问题,您看如何解决?非常感谢!本附件 中是数据。> Sexample=read.csv("D:\Backup\Documents\example\Sexample.csv")
错误: 由"D:\B"开头的字符串中存在'\B',但没有这种逸出号
> Uexample=read.csv("D:\Backup\Documents\example\Uexample.csv")
错误: 由"D:\B"开头的字符串中存在'\B',但没有这种逸出号
> data(Sexample, package = "Ecdat")
警告信息:
In data(Sexample, package = "Ecdat") : 没有‘Sexample’这个数据集
> data(Uexample)
警告信息:
In data(Uexample) : 没有‘Uexample’这个数据集
> fm <- log(gsp) ~ log(pcap) + log(pc) + log(emp) + unemp
> ## the two standard specifications (SEM and SAR) one with FE
> ## and the other with RE:
> ## fixed effects panel with spatial errors
> fespaterr <- spml(fm, data = Sexample, listw = mat2listw(Uexample), model="within", spatial.error="b")
错误于mat2listw(Uexample) : x is not a matrix
> summary(fespaterr)
Spatial panel fixed effects error model
Call:
spml(formula = fm, data = Produc, listw = mat2listw(usaww), model = "within",
    spatial.error = "b")
Residuals:
   Min. 1st Qu.  Median 3rd Qu.    Max.
-0.1250 -0.0238 -0.0035  0.0171  0.1880
Coefficients:
            Estimate Std. Error t-value Pr(>|t|)   
rho        0.5574013  0.0330749 16.8527  < 2e-16 ***
log(pcap)  0.0051438  0.0250109  0.2057  0.83705   
log(pc)    0.2053026  0.0231427  8.8712  < 2e-16 ***
log(emp)   0.7822540  0.0278057 28.1328  < 2e-16 ***
unemp     -0.0022317  0.0010709 -2.0839  0.03717 *  
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> ## random effects panel with spatial lag
> respatlag <- spml(fm, data = Sexample, listw = mat2listw(Uexample), model="random", spatial.error="none", lag=TRUE)
错误于mat2listw(Uexample) : x is not a matrix
> summary(respatlag)
Spatial panel random effects ML model
Call:
spml(formula = fm, data = Produc, listw = mat2listw(usaww), model = "random",
    lag = TRUE, spatial.error = "none")
Residuals:
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
   1.38    1.57    1.70    1.70    1.80    2.13
Error variance parameters:
    Estimate Std. Error t-value Pr(>|t|)  
phi  21.3175     8.3017  2.5678  0.01023 *
Spatial autoregressive coefficient:
       Estimate Std. Error t-value  Pr(>|t|)   
lambda 0.161615   0.029099   5.554 2.793e-08 ***
Coefficients:
               Estimate  Std. Error t-value  Pr(>|t|)   
(Intercept)  1.65814995  0.15071855 11.0016 < 2.2e-16 ***
log(pcap)    0.01294505  0.02493997  0.5190    0.6037   
log(pc)      0.22555376  0.02163422 10.4258 < 2.2e-16 ***
log(emp)     0.67081075  0.02642113 25.3892 < 2.2e-16 ***
unemp       -0.00579716  0.00089175 -6.5009 7.984e-11 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> Sexample
      X          state year      pcap      hwy    water     util        pc    gsp     emp unemp
1     1        ALABAMA 1970  15032.67  7325.80  1655.68  6051.20  35793.80  28418  1010.5   4.7
2     2        ALABAMA 1971  15501.94  7525.94  1721.02  6254.98  37299.91  29375  1021.9   5.2
3     3        ALABAMA 1972  15972.41  7765.42  1764.75  6442.23  38670.30  31303  1072.3   4.7
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2012-11-8 11:30:16
zhangtao 发表于 2012-11-8 08:23
Sexample=read.csv("D:\Backup\Documents\example\Sexample.csv")Uexample=read.csv("D:\Backup\Docume ...
你给的Uexample必须是square matrix
请看function mat2listw的用法
     http://127.0.0.1:13372/library/spdep/html/mat2listw.html
  
mat2listw(x, row.names = NULL, style="M")

x : A square non-negative matrix with no NAs representing spatial weights; may be a matrix of class “sparseMatrix”
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2012-11-8 14:25:01
epoh 发表于 2012-11-8 11:30
你给的Uexample必须是square matrix
请看function mat2listw的用法
     http://127.0.0.1:13372/libra ...
epoh老师,您好!
我是按您的方法,从splm包中下载了produc和usaww两个数据,然后存为
sexample.csv和uexample.csv,然后用read.csv读入进行估计,现在的问题是

Sexample=read.csv("Sexample.csv")

Uexample=read.csv("Uexample.csv")

这两个命令无法读入数据,您运行一下看是什么问题?

Sexample=read.csv("Sexample.csv")

Uexample=read.csv("Uexample.csv")

data(Sexample, package = "Ecdat")data(Uexample)fm <- log(gsp) ~ log(pcap) + log(pc) + log(emp) + unemp## the two standard specifications (SEM and SAR) one with FE## and the other with RE:## fixed effects panel with spatial errorsfespaterr <- spml(fm, data = Sexample, listw = mat2listw(Uexample), model="within", spatial.error="b")summary(fespaterr)## random effects panel with spatial lagrespatlag <- spml(fm, data = Sexample, listw = mat2listw(Uexample), model="random", spatial.error="none", lag=TRUE)summary(respatlag)



二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2012-11-8 14:35:32
> Sexample=read.csv("Sexample.csv")
> Uexample=read.csv("Uexample.csv")
> data(Sexample, package = "Ecdat")
警告信息:
In data(Sexample, package = "Ecdat") : 没有‘Sexample’这个数据集
> data(Uexample)
警告信息:
In data(Uexample) : 没有‘Uexample’这个数据集
> fm <- log(gsp) ~ log(pcap) + log(pc) + log(emp) + unemp
> ## the two standard specifications (SEM and SAR) one with FE
> ## and the other with RE:
> ## fixed effects panel with spatial errors
> fespaterr <- spml(fm, data = Sexample, listw = mat2listw(Uexample), model="within", spatial.error="b")
错误于mat2listw(Uexample) : x is not a matrix
> summary(fespaterr)
错误于summary(fespaterr) :
  在为'summary'函数选择方法时评估'object'参数出了错: 错误: 找不到对象'fespaterr'

> ## random effects panel with spatial lag
> respatlag <- spml(fm, data = Sexample, listw = mat2listw(Uexample), model="random", spatial.error="none", lag=TRUE)
错误于mat2listw(Uexample) : x is not a matrix
> summary(respatlag)
错误于summary(respatlag) :
  在为'summary'函数选择方法时评估'object'参数出了错: 错误: 找不到对象'respatlag'

>
> Example
错误: 找不到对象'Example'
> Sexample
      X          state year      pcap      hwy    water     util        pc    gsp     emp unemp
1     1        ALABAMA 1970  15032.67  7325.80  1655.68  6051.20  35793.80  28418  1010.5   4.7
2     2        ALABAMA 1971  15501.94  7525.94  1721.02  6254.98  37299.91  29375  1021.9   5.2
3     3        ALABAMA 1972  15972.41  7765.42  1764.75  6442.23  38670.30  31303  1072.3   4.7
4     4        ALABAMA 1973  16406.26  7907.66  1742.41  6756.19  40084.01  33430  1135.5   3.9
5     5        ALABAMA 1974  16762.67  8025.52  1734.85  7002.29  42057.31  33749  1169.8   5.5
6     6        ALABAMA 1975  17316.26  8158.23  1752.27  7405.76  43971.71  33604  1155.4   7.7
7     7        ALABAMA 1976  17732.86  8228.19  1799.74  7704.93  50221.57  35764  1207.0   6.8
8     8        ALABAMA 1977  18111.93  8365.67  1845.11  7901.15  51084.99  37463  1269.2   7.4
9     9        ALABAMA 1978  18479.74  8510.64  1960.51  8008.59  52604
本文来自: 人大经济论坛 S-Plus&R专版 版,详细出处参考: https://bbs.pinggu.org/forum.php? ... 5&from^^uid=11232
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2012-11-8 14:36:08
> Uexample
                X ALABAMA   ARIZONA  ARKANSAS CALIFORNIA  COLORADO CONNECTICUT  DELAWARE FLORIDA GEORGIA     IDAHO  ILLINOIS   INDIANA      IOWA    KANSAS KENTUCKY LOUISIANA     MAINE  MARYLAND MASSACHUSETTS MICHIGAN MINNESOTA
1         ALABAMA   0.000 0.0000000 0.0000000       0.00 0.0000000         0.0 0.0000000    0.25   0.250 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000    0.000 0.0000000 0.0000000 0.0000000     0.0000000     0.00 0.0000000
2         ARIZONA   0.000 0.0000000 0.0000000       0.20 0.2000000         0.0 0.0000000    0.00   0.000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000    0.000 0.0000000 0.0000000 0.0000000     0.0000000     0.00 0.0000000
3        ARKANSAS   0.000 0.0000000 0.0000000       0.00 0.0000000         0.0 0.0000000    0.00   0.000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000    0.000 0.1666667 0.0000000 0.0000000     0.0000000     0.00 0.0000000
4      CALIFORNIA   0.000 0.3333333 0.0000000       0.00 0.0000000         0.0 0.0000000    0.00   0.000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000    0.000 0.0000000 0.0000000 0.0000000     0.0000000     0.00 0.0000000
5        COLORADO   0.000 0.1428571 0.0000000       0.00 0.0000000         0.0 0.0000000    0.00   0.000 0.0000000 0.0000000 0.0000000 0.0000000 0.1428571    0.000 0.0000000 0.0000000 0.0000000     0.0000000     0.00 0.0000000
6     CONNECTICUT   0.000 0.0000000 0.0000000       0.00 0.0000000         0.0 0.0000000    0.00   0.000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000    0.000 0.0000000 0.0000000 0.0000000     0.3333333     0.00 0.0000000
7        DELAWARE   0.000 0.0000000 0.0000000       0.00 0.0000000         0.0 0.0000000    0.00   0.000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000    0.000 0.0000000 0.0000000 0.3333333     0.0000000     0.00 0.0000000
8         FLORIDA   0.500 0.0000000 0.0000000       0.00 0.0000000         0.0 0.0000000    0.00   0.500 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000    0.000 0.0000000 0.0000000 0.0000000     0.0000000     0.00 0.0000000
9         GEORGIA   0.200 0.0000000 0.0000000       0.00 0.0000000         0.0 0.0000000    0.20   0.000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000    0.000 0.0000000 0.0000000 0.0000000     0.0000000     0.00 0.0000000
10          IDAHO   0.000 0.0000000 0.0000000       0.00 0.0000000         0.0 0.0000000    0.00   0.000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000    0.000 0.0000000 0.0000000 0.0000000     0.0000000     0.00 0.0000000
11       ILLINOIS   0.000 0.0000000 0.0000000       0.00 0.0000000         0.0 0.0000000    0.00   0.000 0.0000000 0.0000000 0.2000000 0.2000000 0.0000000    0.200 0.0000000 0.0000000 0.0000000     0.0000000     0.00 0.0000000
12        INDIANA   0.000 0.0000000 0.0000000       0.00 0.0000000         0.0 0.0000000    0.00   0.000 0.0000000 0.2500000 0.0000000 0.0000000 0.0000000    0.250 0.0000000 0.0000000 0.0000000     0.0000000     0.25 0.0000000
13           IOWA   0.000 0.0000000 0.0000000       0.00 0.0000000         0.0 0.0000000    0.00   0.000 0.0000000 0.1666667 0.0000000 0.0000000 0.0000000    0.000 0.0000000 0.0000000 0.0000000     0.0000000     0.00 0.1666667
14         KANSAS   0.000 0.0000000 0.0000000       0.00 0.2500000         0.0 0.0000000    0.00   0.000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000    0.000 0.0000000 0.0000000 0.0000000     0.0000000     0.00 0.0000000
15       KENTUCKY   0.000 0.0000000 0.0000000       0.00 0.0000000         0.0 0.0000000    0.00   0.000 0.0000000 0.1428571 0.1428571 0.0000000 0.0000000    0.000 0.0000000 0.0000000 0.0000000     0.0000000     0.00 0.0000000
16      LOUISIANA   0.000 0.0000000 0.3333333       0.00 0.0000000         0.0 0.0000000    0.00   0.000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000    0.000 0.0000000 0.0000000 0.0000000     0.0000000     0.00 0.0000000
17          MAINE   0.000 0.0000000 0.0000000       0.00 0.0000000         0.0 0.0000000    0.00   0.000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000    0.000 0.0000000 0.0000000 0.0000000     0.0000000     0.00 0.0000000
18       MARYLAND   0.000 0.0000000 0.0000000       0.00 0.0000000         0.0 0.2500000    0.00   0.000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000    0.000 0.0000000 0.0000000 0.0000000     0.0000000     0.00 0.0000000
19  MASSACHUSETTS   0.000 0.0000000 0.0000000       0.00 0.0000000         0.2 0.0000000    0.00   0.000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000    0.000 0.0000000 0.0000000 0.0000000     0.0000000     0.00 0.0000000
20       MICHIGAN   0.000 0.0000000 0.0000000       0.00 0.0000000         0.0 0.0000000    0.00   0.000 0.0000000 0.0000000 0.3333333 0.0000000 0.0000000    0.000 0.0000000 0.0000000 0.0000000     0.0000000     0.00 0.0000000
21      MINNESOTA   0.000 0.0000000 0.0000000       0.00 0
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2012-11-8 14:37:41
> Sexample=read.csv("Sexample.csv")
> Uexample=read.csv("Uexample.csv")
> data(Sexample, package = "Ecdat")
警告信息:
In data(Sexample, package = "Ecdat") : 没有‘Sexample’这个数据集
> data(Uexample)
警告信息:
In data(Uexample) : 没有‘Uexample’这个数据集
epoh老师,您好!
明明uexample and sexample两个数据集读进去了,为什么会提示
两个数据集找不到呢?
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2012-11-8 15:10:22
epoh 发表于 2012-11-8 11:30
你给的Uexample必须是square matrix
请看function mat2listw的用法
     http://127.0.0.1:13372/libra ...
epoh老师,您好!
现在的问题是无法读入uexample and sexample这两个数据,
我命令都对,怎么会读不进去呢?
但是输入 fix(Sexample)提示数据读进去了。
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2012-11-8 16:22:28
zhangtao 发表于 2012-11-8 15:10
epoh老师,您好!
现在的问题是无法读入uexample and sexample这两个数据,
我命令都对,怎么会读不进去 ...
library(splm)
data(Produc, package = "Ecdat")
data(usaww)
write.csv(Produc,"Sexample.csv",row.names = FALSE,col.names = TRUE)
write.csv(usaww,"Uexample.csv",row.names = FALSE,col.names = TRUE)
Sexample=read.csv("Sexample.csv")
Uexample=read.csv("Uexample.csv")
Uexample=data.matrix(Uexample)
fm <- log(gsp) ~ log(pcap) + log(pc) + log(emp) + unemp
## the two standard specifications (SEM and SAR) one with FE
## and the other with RE:
## fixed effects panel with spatial errors
fespaterr <- spml(fm, data = Sexample, listw = mat2listw(Uexample), model="within", spatial.error="b")
summary(fespaterr)
########
Spatial panel fixed effects error model

Call:
spml(formula = fm, data = Sexample, listw = mat2listw(Uexample),
    model = "within", spatial.error = "b")

Residuals:
   Min. 1st Qu.  Median 3rd Qu.    Max.
-0.1250 -0.0238 -0.0035  0.0171  0.1880

Coefficients:
            Estimate Std. Error t-value Pr(>|t|)   
rho        0.5574013  0.0330749 16.8527  < 2e-16 ***
log(pcap)  0.0051438  0.0250109  0.2057  0.83705   
log(pc)    0.2053026  0.0231427  8.8712  < 2e-16 ***
log(emp)   0.7822540  0.0278057 28.1328  < 2e-16 ***
unemp     -0.0022317  0.0010709 -2.0839  0.03717 *  
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#########
## random effects panel with spatial lag
respatlag <- spml(fm, data = Sexample, listw = mat2listw(Uexample), model="random", spatial.error="none", lag=TRUE)
summary(respatlag)
########
Spatial panel random effects ML model

Call:
spml(formula = fm, data = Sexample, listw = mat2listw(Uexample),
    model = "random", lag = TRUE, spatial.error = "none")

Residuals:
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
   1.38    1.57    1.70    1.70    1.80    2.13

Error variance parameters:
    Estimate Std. Error t-value Pr(>|t|)  
phi  21.3175     8.2937  2.5703  0.01016 *

Spatial autoregressive coefficient:
       Estimate Std. Error t-value Pr(>|t|)   
lambda 0.161615   0.029041  5.5651 2.62e-08 ***

Coefficients:
               Estimate  Std. Error t-value  Pr(>|t|)   
(Intercept)  1.65814995  0.15071855 11.0016 < 2.2e-16 ***
log(pcap)    0.01294505  0.02493997  0.5190    0.6037   
log(pc)      0.22555376  0.02163422 10.4258 < 2.2e-16 ***
log(emp)     0.67081075  0.02642113 25.3892 < 2.2e-16 ***
unemp       -0.00579716  0.00089175 -6.5009 7.984e-11 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2012-11-8 19:43:49
epoh 发表于 2012-11-8 16:22
library(splm)
data(Produc, package = "Ecdat")
data(usaww)
epoh老师,您好!
为什么加上row.names = FALSE这一行程序就可以
行了呢?您是怎么知道的呢?
非常感谢!
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2012-11-9 18:40:56
zhangtao 发表于 2012-11-8 19:43
epoh老师,您好!
为什么加上row.names = FALSE这一行程序就可以
行了呢?您是怎么知道的呢?
write.csv预设是 row.names = TRUE,col.names = TRUE
这时候write.csv(Produc,"Sexample.csv")
会把第一行column 1,2,3,....,加进来
      X          state year      pcap      hwy    water     util  ...
1     1        ALABAMA 1970  15032.67  7325.80  1655.68  6051.20  ...
2     2        ALABAMA 1971  15501.94  7525.94  1721.02  6254.98  ...
3     3        ALABAMA 1972  15972.41  7765.42  1764.75  6442.23  ...
造成dimension不对,所以要改成底下:
write.csv(Produc,"Sexample.csv",row.names = FALSE,col.names = TRUE)

编程中,随时都要检查读入的数据是否正确,
以确保程序的运行.
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2012-11-9 22:44:06
epoh 发表于 2012-11-9 18:40
write.csv预设是 row.names = TRUE,col.names = TRUE
这时候write.csv(Produc,"Sexample.csv")
会把第一 ...
graphics.off()
library(strucchange)
library(longmemo) # not used
postscript(file="c:/res-teach/xiamen12-06/figs/fig-9.2.eps",
horizontal=F,width=6,height=6)
epoh老师,您好!
这个postscript(......)和graphics.off()这两个命令是什么意思?

> da=read.table("m-intc7308.txt",header=T)
>  library(fGarch) # Load the package
载入需要的程辑包:timeDate
载入需要的程辑包:timeSeries
载入需要的程辑包:fBasics
载入需要的程辑包:MASS
载入程辑包:‘fBasics’
The following object(s) are masked from ‘package:base’:
    norm
>  intc=log(da[,2]+1)
>  m1=garchFit(intc~garch(1,0),data=intc,trace=F)
>  summary(m1) # Obtain results
错误于summary(m1) :
  在为'summary'函数选择方法时评估'object'参数出了错: 错误: 找不到对象'm1'

>
还有,以上代码错在什么地方?
m-intc7308.txt
大小:(7.99 KB)

 马上下载



二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2012-11-10 17:21:38
zhangtao 发表于 2012-11-9 22:44
graphics.off()
library(strucchange)
library(longmemo) # not used
graphics.off() : shuts down all open graphics devices
                意思是关闭所有图形窗口,打算将下一个图形写入fig-9.2.eps
postscript() : open a postscript() device with a filename ending in .eps

example:
  graphics.off()
  postscript("test.eps")
  plot(rnorm(100))
  dev.off()

这时候就会产生一个test.eps文件
当然你也可以由图型窗口
file\save as \postscript\....
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2012-11-10 17:56:23
zhangtao 发表于 2012-11-9 22:44
graphics.off()
library(strucchange)
library(longmemo) # not used
da=read.table("m-intc7308.txt",header=F)
intc=log(da[,2]+1)
m1=garchFit(~garch(1,0),data=intc,trace=F)
summary(m1) # Obtain results
Title:
GARCH Modelling

Call:
garchFit(formula = ~garch(1, 0), data = intc, trace = F)

Mean and Variance Equation:
data ~ garch(1, 0)
<environment: 0x08595964>
[data = intc]

Conditional Distribution:
norm

Coefficient(s):
     mu    omega   alpha1  
0.01657  0.01249  0.36345  

Std. Errors:
based on Hessian

Error Analysis:
        Estimate  Std. Error  t value Pr(>|t|)   
mu      0.016570    0.006161    2.689  0.00716 **
omega   0.012490    0.001549    8.061 6.66e-16 ***
alpha1  0.363447    0.131598    2.762  0.00575 **
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Log Likelihood:
230.2423    normalized:  0.6189309

Description:
Sat Nov 10 17:36:51 2012 by user: pro


Standardised Residuals Tests:
                                Statistic p-Value     
Jarque-Bera Test   R    Chi^2  122.404   0           
Shapiro-Wilk Test  R    W      0.9647628 8.274108e-08
Ljung-Box Test     R    Q(10)  13.72604  0.1858587   
Ljung-Box Test     R    Q(15)  22.31714  0.09975386  
Ljung-Box Test     R    Q(20)  23.88257  0.2475594   
Ljung-Box Test     R^2  Q(10)  12.50025  0.25297     
Ljung-Box Test     R^2  Q(15)  30.11276  0.01152131  
Ljung-Box Test     R^2  Q(20)  31.46404  0.04935483  
LM Arch Test       R    TR^2   22.036    0.0371183   

Information Criterion Statistics:
      AIC       BIC       SIC      HQIC
-1.221733 -1.190129 -1.221861 -1.209182
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2012-11-11 19:12:01
epoh 发表于 2012-11-10 17:56
da=read.table("m-intc7308.txt",header=F)
intc=log(da[,2]+1)
m1=garchFit(~garch(1,0),data=intc, ...
epoh老师,您好!
     在read.csv这个命令中,row.names 和 col.names这两个选项的参数如何设定?
以下帮助我没有看懂,不知说的是什么意思。如果我不想读入行名和列名,row.names 和 col.names这两个选项的参数如何设定?
> read.csv(Sexample.csv, fill = TRUE, header = FALSE,row.names=FALSE, col.names = FALSE, sep = ""))
错误: 意外的')'在"read.csv(Sexample.csv, fill = TRUE, header = FALSE,row.names=FALSE, col.names = FALSE, sep = ""))"里
> fix(Sexample.csv)
> fix(Sexample.csv)
> read.csv(Sexample.csv, fill = TRUE, header = FALSE,row.names=FALSE, col.names = FALSE, sep = "")
错误于read.table(file = file, header = header, sep = sep, quote = quote,  :
  'file'的值必需是字符串或联结
> read.csv("Sexample.csv", fill = TRUE, header = FALSE,row.names=FALSE, col.names = FALSE, sep = "")
错误于read.table(file = file, header = header, sep = sep, quote = quote,  :
  列的数目比列的名字要多
> row.names a vector of row names. This can be a vector giving the actual row names, or a single number giving the column of the table which contains the row names, or character string giving the name of the table column containing the row names.

If there is a header and the first row contains one fewer field than the number of columns, the first column in the input is used for the row names. Otherwise if row.names is missing, the rows are numbered.

Using row.names = NULL forces row numbering. Missing or NULL row.names generate row names that are considered to be ‘automatic’ (and not preserved by as.matrix).

col.names a vector of optional names for the variables. The default is to use "V" followed by the column number.

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2012-11-12 15:41:40
zhangtao 发表于 2012-11-11 19:12
epoh老师,您好!
     在read.csv这个命令中,row.names 和 col.names这两个选项的参数如何设定?
以 ...
Testcsv.csv  
testcsv.rar
大小:(206 Bytes)

 马上下载

本附件包括:

  • testcsv.csv


底下是testcsv.csv的数据:
   make   model mpg weight price
1   AMC Concord  22   2930  4099
2   AMC   Pacer  17   3350  4749
3   AMC  Spirit  22   2640  3799
4 Buick Century  20   3250  4816
5 Buick Electra  15   4080  7827

#read.csv("testcsv.csv", header = TRUE)
#header=T的意思是第一行被认为是header(names of the variables ),而不是数据.
a1=read.csv("testcsv.csv", header = TRUE)
a1
   make   model mpg weight price
1   amc concord  22   2930  4099
2   amc   oacer  17   3350  4749
3   amc  spirit  22   2640  3799
4 buick century  20   3250  4816
5 buick electra  15   4080  7827

##read.csv("testcsv.csv", header =  FALSE)
#header= FALSE的意思是第一行被认为是数据.
#col.names a vector of optional names for the variables.
#The default is to use "V" followed by the column number.
a2=read.csv("testcsv.csv", header = FALSE)
a2
     V1      V2  V3     V4    V5
1  make   model mpg weight price
2   amc concord  22   2930  4099
3   amc   oacer  17   3350  4749
4   amc  spirit  22   2640  3799
5 buick century  20   3250  4816
6 buick electra  15   4080  7827

#read.csv(),预设就是row.names=NULL
#所以同a1
a3=read.csv("testcsv.csv", header = TRUE,row.names=NULL)
a3
   make   model mpg weight price
1   amc concord  22   2930  4099
2   amc   oacer  17   3350  4749
3   amc  spirit  22   2640  3799
4 buick century  20   3250  4816
5 buick electra  15   4080  7827
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2012-11-12 21:25:44
epoh 发表于 2012-11-12 15:41
Testcsv.csv  
底下是testcsv.csv的数据:
   make   model mpg weight price
datana.rar
大小:(1.7 KB)

 马上下载

本附件包括:

  • datana.xls


epoh老师,您好!
     附件中的数据缺失了1990-1993四年的数据,想用插值法补齐,
您看在R中如何操作?
非常感谢!

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群