[R] error calling Winbugs using R2WinBugs to run a multi-level model
Saana Isojunno
saana.isojunno at googlemail.com
Thu Jun 7 16:50:38 CEST 2012
Thanks for the suggestions!
Unfortunately I get same trap whether I input the data as a named
list, list of the names, or text file. I tried the three with and
without transposing the matrices (I didn't change the model structure
indexing but this should appear as an indexing error later on).
Good news is that I experimented with downloading Jags and the model
fits fine to the same data directly from r, calling the R2Jags library
with minimal changes to any of my scripts. I only had to define couple
of more nodes in the model in order to monitor them.
I'll send you the txt files in a separate email. Thanks again for your interest!
Saana
On 6 June 2012 18:17, Uwe Ligges <ligges at statistik.tu-dortmund.de> wrote:
>
>
> On 06.06.2012 16:51, ilai wrote:
>>
>> Untested because I don't have (use) winbugs and you didn't provide dat*.
>> But consider
>> a<- 4 ; f<- 6
>> list('a','f')
>> list(a,f)
>> list(a=a,f=f)
>>
>> My guess is you wanted sp.data to be a named list, not a list of names...
>
>
>
> That's also OK, from ?bugs.data:
>
> data: either a named list (names corresponding to variable names in
> the ‘model.file’) of the data for the ‘WinBUGS’ model, _or_
> (which is not recommended and unsafe) a vector or list of the
> names of the data objects used by the model
>
>
>
> To really now what is going on, I'd need the model file and the data. My
> suspicion is that the matrices have to be transposed.
>
> Best,
> Uwe Ligges
>
>
>> HTH
>>
>>
>> On Wed, Jun 6, 2012 at 4:12 AM, Saana Isojunno<
>> saana.isojunno at googlemail.com> wrote:
>>
>>> Dear all,
>>>
>>> I'm calling Winbugs (1.4.3) through R2WinBugs (2.1-18 coda_0.14-7) to
>>> fit a switching random walk model, but come up with an instant trap
>>> with the log only displaying 'check('.
>>>
>>> I will paste the trap with session info below; I'd be very grateful
>>> for any ideas.
>>>
>>> Couple of leads:
>>>
>>> 1. I presume the problem relates to the r package itself or the way I
>>> call bugs(), because I can use the same text files specifying the
>>> model and data directly in Winbugs and it runs fine (i.e syntax ok,
>>> compilation ok, updates slow but no traps).
>>>
>>> 2. The problem occurs in r only when I try to fit the model to
>>> multiple individuals, i.e. the data contains a matrix of step lengths
>>> (rows) and individuals (columns) instead of a vector for just one
>>> individual. I get the same error message regardless of the number of
>>> data rows in each column (I even tried just one).
>>>
>>> The model loops over the path of each animal, estimating a hidden
>>> movement state and their parameters. For 4 individuals with 100 data
>>> points each the data looks something like this:
>>>
>>> dat1 : num 100
>>> dat2 : int 4
>>> dat3 : num [1:4] 8 4 2 5
>>> dat4 : num [1:100, 1:4] 1 1 1 1 1 2 2 2 2 2 ...
>>> dat5 : num [1:100, 1:4] 2 2 2 2 2 1 2 2 2 2 ...
>>> dat6 : num [1:100, 1:4] 16 34.3 33.5 27.9 14.9 ...
>>> dat7 : num [1:100, 1:4] 0.357 0.474 0.487 0.495 0.524 ...
>>> dat8 : num [1:50, 1:4] 36.4 294.5 24.4 21.1 422.8 ...
>>>
>>> This is how I've called WinBugs in r:
>>>
>>> # write data to text file
>>> sp.data = list("dat1","dat2","dat3","dat4","dat5","dat6","dat7","dat8")
>>> bugs.data(sp.data, digits=5, data.file="dir1\\data1.txt")
>>>
>>> # test the model runs
>>> fit =
>>>
>>> bugs(data=paste("C:\\Users\\User1\\Documents\\dir1\\data1.txt",dataFile,sep=""),
>>> inits=NULL, parameters.to.save=list('par1','par2','par3'),
>>> model.file=modelFile,
>>> debug=TRUE, n.chains=3, n.iter=20, n.burnin=3, n.thin=1,
>>> digits=4)
>>>
>>> ## The trap
>>>
>>> incompatible copy
>>>
>>> BugsScript.Action.Do [00000436H]
>>> .a BugsScript.Action [025B6790H]
>>> .argNum INTEGER 0
>>> .bugsCommands ARRAY 240 OF CHAR 7877X, 75A5X, 0B17X, 3701X
>>> ...
>>> .p ARRAY 3, 120 OF CHAR Elements
>>> .s BugsScanners.Scanner Fields
>>> .scriptCommand ARRAY 240 OF CHAR "#Bugs:check" ...
>>> .vectorName BOOLEAN FALSE
>>> Services.Exec [00000136H]
>>> .a Services.Action [025B6790H]
>>> .t POINTER [64E10170H]
>>> Services.IterateOverActions [000002F4H]
>>> .p Services.Action [025B6790H]
>>> .t POINTER NIL
>>> .time LONGINT 4375656
>>> Services.StdHook.Step [0000034DH]
>>> .h Services.StdHook [0248E380H]
>>> 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 1311298
>>> Kernel.Try [00003A61H]
>>> .a INTEGER 1311298
>>> .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 1664639202
>>> .s ARRAY 256 OF SHORTCHAR "" ...
>>> .w INTEGER 1970768325
>>> .wParam INTEGER 1
>>> .wnd INTEGER 1311298
>>> <system> (pc=75778816H, fp=0027FB38H)
>>> <system> (pc=7577898DH, fp=0027FBB0H)
>>> <system> (pc=75778AB8H, fp=0027FC14H)
>>> <system> (pc=757790E2H, fp=0027FC24H)
>>> 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
>>>
>>>
>>>
>>>
>>>
>>> ## my current R session specs:
>>>
>>> R version 2.15.0 (2012-03-30)
>>> Platform: x86_64-pc-mingw32/x64 (64-bit)
>>>
>>> locale:
>>> [1] LC_COLLATE=English_United Kingdom.1252
>>> [2] LC_CTYPE=English_United Kingdom.1252
>>> [3] LC_MONETARY=English_United Kingdom.1252
>>> [4] LC_NUMERIC=C
>>> [5] LC_TIME=English_United Kingdom.1252
>>>
>>> attached base packages:
>>> [1] stats graphics grDevices utils datasets methods base
>>>
>>> other attached packages:
>>> [1] R2WinBUGS_2.1-18 coda_0.14-7 lattice_0.20-6
>>>
>>> loaded via a namespace (and not attached):
>>> [1] grid_2.15.0 tools_2.15.0
>>>
>>>
>>>
>>>
>>> ## also tried these specs:
>>>
>>> R version 2.13.2 (2011-09-30)
>>> Platform: x86_64-pc-mingw32/x64 (64-bit)
>>>
>>> locale:
>>> [1] LC_COLLATE=English_United Kingdom.1252
>>> [2] LC_CTYPE=English_United Kingdom.1252
>>> [3] LC_MONETARY=English_United Kingdom.1252
>>> [4] LC_NUMERIC=C
>>> [5] LC_TIME=English_United Kingdom.1252
>>>
>>> attached base packages:
>>> [1] stats graphics grDevices utils datasets methods base
>>>
>>> other attached packages:
>>> [1] R2WinBUGS_2.1-18 coda_0.14-4 lattice_0.19-33
>>>
>>> loaded via a namespace (and not attached):
>>> [1] grid_2.13.2 tools_2.13.2
>>>
>>>
>>>
>>>
>>> Thank you!
>>>
>>> Saana Isojunno
>>>
>>> PhD candidate
>>> Scottish Oceans Institute
>>> University of St Andrews
>>> Scotland
>>>
>>> ______________________________________________
>>> 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.
>>>
>>
>> [[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.
--
-----------------------------------------------------
e-mail saana.isojunno at gmail.com
tel +44 7 564 606 949
address 22 West Forth Street
Cellardyke
ANSTRUTHER
KY10 3HL
UK
More information about the R-help
mailing list