Sorry for the late reply, maybe its is still of some help. See comments
below.
Sotiris Adamakis wrote:> Appologies for cross-posting
>
>
>
> Dear R users,
>
> I am using R2WinBUGS to call WinBUGS from R. After loading data, model, and
initial values I call this command
>
> res <- bugs(data = dfile, inits = list(ifile), parameters.to.save =
c("beta"), model.file = mfile, working.directory = tdir, n.thin =
nthin, n.chains = 1, n.iter = niterations*nthin, n.burnin = 0, DIC = F, debug =
T, save.history=F)
>
> which opens WinBUGS and executes the following log file:
>
>
>
> display(log)
>
> check(C:/Documents and Settings/sbadamakis/Desktop/model_4/model_4.txt)
>
> model is syntactically correct
>
> data(C:/Documents and Settings/sbadamakis/Desktop/model_4/output1/data.txt)
>
> data loaded
>
> compile(1)
>
> model compiled
>
> inits(1,C:/Documents and
Settings/sbadamakis/Desktop/model_4/output1/inits1.txt)
>
> model is initialized
>
> gen.inits()
>
> command #Bugs:gen.inits cannot be executed (is greyed out)
>
> thin.updater(1)
>
> update(0)
>
> set(beta)
>
> update(20)
>
> coda(*,C:/Documents and Settings/sbadamakis/Desktop/model_4/output1/coda)
>
> stats(*)
>
> Node statistics
>
> node mean sd MC error 2.5% median 97.5% start sample
>
> beta[1] 1.588 0.009812 0.003936 1.579 1.584 1.607 1 20
>
> beta[2] -0.04272 0.00263 0.001137 -0.04592 -0.0433 -0.03688 1 20
>
> beta[3] -0.07878 8.531E-4 2.829E-4 -0.07962 -0.07833 -0.07699 1 20
>
> beta[4] -0.3035 0.01016 0.004509 -0.3194 -0.3028 -0.2841 1 20
>
> beta[5] 1.241 0.00854 0.002739 1.228 1.242 1.258 1 20
>
> beta[6] -4.155 0.01242 0.005405 -4.174 -4.152 -4.132 1 20
>
> beta[7] 0.08322 0.001485 6.379E-4 0.08201 0.0824 0.08608 1 20
>
> beta[8] -3.001 0.009335 0.003318 -3.013 -3.004 -2.981 1 20
>
> beta[9] 0.07953 7.547E-4 3.198E-4 0.07777 0.07932 0.08035 1 20
>
> save(C:/Documents and Settings/sbadamakis/Desktop/model_4/output1/log.odc)
>
> save(C:/Documents and Settings/sbadamakis/Desktop/model_4/output1/log.txt)
>
>
>
> So far so good. After the end of the last line of the log file, WinBUGS
should close and the bugs function in R should return the Markov chain values of
the "beta" parameters. The problem is that it doesn't and WinBUGS
stays infinitely open. This is a big problem as I have written a code in R and I
want to call the bugs function several times. Do you know if there's an
option in the bugs function in R to FORCE WinBUGS to close?
You can close WinBUGS and everything should be fine - or just set debug
= FALSE rather than debug = TRUE in your bugs() call.
>
> Furthermore, some other times (the same code!!!) produces the following
TRAP message
>
> undefined real result
>
> GraphStack.Node.Value [00000C9AH]
> .i INTEGER 6
> .j INTEGER 2
> .k INTEGER 1
> .node GraphStack.Node [0138C5D0H]
> .op INTEGER 6
> .p GraphNodes.Node [01544D30H]
> .top INTEGER 0
> .work ARRAY 10 OF REAL
> [0] REAL inf
> [1] REAL inf
> [2] REAL inf
> [3] REAL 1.30212336033939
> [4] REAL 4.534462964264759
> [5] REAL 1.769649991139459E+167
> [6] REAL 1.792592453177908E-307
> [7] REAL 9.94060079432588E-321
> [8] REAL 5.474495960374562E+67
> [9] REAL 5.257527858867595E-308
> MonitorsSamples.StdMonitor.Update [0000023DH]
> .blocks POINTER NIL
> .i INTEGER 1655837286
> .index INTEGER 7
> .monitor MonitorsSamples.StdMonitor [02155B50H]
> .numBlocks INTEGER 0
> .value REAL 1.0
> SamplesMonitors.Monitor.Update [0000091BH]
> .chain INTEGER 0
> .i INTEGER 4480
> .monitor SamplesMonitors.Monitor [01C0A4E0H]
> .size INTEGER 6780
> SamplesIndex.Monitor.Update [0000030CH]
> .chain INTEGER 0
> .cursor SamplesIndex.List [01AB2E30H]
> .monitor SamplesIndex.Monitor [01C59510H]
> .sampleMonitor SamplesMonitors.Monitor [01C0A4E0H]
> UpdaterActions.UpdateMonitors [0000011CH]
> .chain INTEGER 0
> .monitor UpdaterActions.Monitor [01C59510H]
> BugsCmds.Action.Step [00000BCAH]
> .a BugsCmds.Action [011D40C0H]
> .chain INTEGER 0
> .i INTEGER 8
> .j INTEGER 1000
> .numChains INTEGER 1
> BugsCmds.Action.Do [00000C58H]
> .a BugsCmds.Action [011D40C0H]
> .elapsedTime LONGINT 62EC21F162EB0384H
> .profileList ARRAY 2024 OF CHAR "" ...
> .res INTEGER 1635734111
> .s ARRAY 120 OF CHAR 3X ...
> Services.Exec [00000136H]
> .a Services.Action [011D40C0H]
> .t POINTER [62EB0384H]
> Services.IterateOverActions [000002F4H]
> .p Services.Action [011D40C0H]
> .t POINTER NIL
> .time LONGINT 300843187
> Services.StdHook.Step [0000034DH]
> .h Services.StdHook [0101E380H]
> HostWindows.Idle [00004A86H]
> .focus BOOLEAN FALSE
> .tick Controllers.TickMsg Fields
> .w HostWindows.Window NIL
> HostMenus.TimerTick [00003422H]
> .lParam INTEGER 0
> .ops Controllers.PollOpsMsg Fields
> .wParam INTEGER 1
> .wnd INTEGER 1770006
> Kernel.Try [00003A61H]
> .a INTEGER 1770006
> .b INTEGER 1
> .c INTEGER 0
> .h PROCEDURE HostMenus.TimerTick
> HostMenus.ApplWinHandler [00003841H]
> .Proc PROCEDURE NIL
> .hit BOOLEAN FALSE
> .lParam INTEGER 0
> .message INTEGER 275
> .res INTEGER 4243644
> .s ARRAY 256 OF SHORTCHAR "?B", 1X ...
> .w INTEGER 2147348480
> .wParam INTEGER 1
> .wnd INTEGER 1770006
> <system> (pc=7E418733H, fp=0022FB84H)
> <system> (pc=7E418815H, fp=0022FBECH)
> <system> (pc=7E4189CCH, fp=0022FC4CH)
> <system> (pc=7E4196C6H, fp=0022FC5CH)
> HostMenus.Loop [00003BDEH]
> .done BOOLEAN FALSE
> .f SET {0..5}
> .n INTEGER 0
> .res INTEGER 0
> .w HostWindows.Window NIL
> Kernel.Start [00002B8CH]
> .code PROCEDURE HostMenus.Loop
>
>
> Is there anyone who can explain what does this mean and how to understand
trap messages? For me, it seems that the problem lies here:
>
> .work ARRAY 10 OF REAL
> [0] REAL inf
> [1] REAL inf
> [2] REAL inf
> [3] REAL 1.30212336033939
> [4] REAL 4.534462964264759
> [5] REAL 1.769649991139459E+167
> [6] REAL 1.792592453177908E-307
> [7] REAL 9.94060079432588E-321
> [8] REAL 5.474495960374562E+67
> [9] REAL 5.257527858867595E-308
>
> where it says that it produces some inf parameter values. I do not
understand why this happens as the program was working fine for 5*10^5
iterations. I tried to change the Seed values but there was no use.
This is a BUGS rather than an R question, hence please ask on their
mailing list.
Anyway, without having your model file etc, I can guess that you have
some division by almost zero from sampling from some distribution that
may return some extremely small values close to zero.
Uwe Ligges
> A bit of background:
> 1) I am running multilevel models for small area estimation and the above
problems seem to appear only with the spatial random effects model. The
spatial+non-spatial random effects model seems to behave properly without any
problems.
>
> 2) As mentioned above the program was working fine for more than 500000
iterations. This means that I got no trap messages and I called the bugs
function for more than 10 times without any problems.
>
> It's so frustrating...
>
> Kind regards,
> Sotiris
>
>
>
>
> Dr. Sotiris Adamakis
> Senior Statistician - Ipsos MORI
>
> T +44 20 7347 3828
> s<mailto:ssotiris.adamakis at
ipsos.com>otiris.adamakis<mailto:ssotiris.adamakis at
ipsos.com>@ipsos.com<mailto:ssotiris.adamakis at ipsos.com>
> www.ipsos-mori.com<http://www.ipsos-mori.com/>
>
> 79-81 Borough Road, London, SE1 1FY
>
> ________________________________
>
===============================================================================================>
This e-mail and all attachments it may contain is confidential and intended
solely for the use of the individual to whom it is addressed. Any views or
opinions presented are solely those of the author and do not necessarily
represent those of Ipsos MORI and its associated companies. If you are not the
intended recipient, be advised that you have received this e-mail in error and
that any use, dissemination, printing, forwarding or copying of this e-mail is
strictly prohibited. Please contact the sender if you have received this e-mail
in error.
>
> Market & Opinion Research International Ltd (trading as Ipsos MORI),
Registered in England and Wales No. 948470, 79-81 Borough Road, London SE1 1FY,
United Kingdom. VAT reg no. 443932151. Email: ukinfo at ipsos.com
>
>
===============================================================================================>
> [[alternative HTML version deleted]]
>
>
>
> ------------------------------------------------------------------------
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.