Huggins Full Heterogeneity with varying sampling occasions

posts related to the RMark library, which may not be of general interest to users of 'classic' MARK

Huggins Full Heterogeneity with varying sampling occasions

Postby Triciaserow » Thu Jan 19, 2017 5:50 pm

Hi,

I was trying to run a Huggins Full Heterogeneity (HugFullHet) model with group effect. However, these 2 "groups" were actually "strata" among the population. To be more specific, I was trying to estimate abundance of a species from 2 grids in my study area. I looked over "multi-strata" model but I wasn't interested in their transition between different "states". Not many movements or transitions occurred during sampling so I don't think multi-strata is the type of model I need.

As I tried to apply HugFullHet to my data, it seemed that Huggins required sampling occasions to be consistent among groups. My data from the two grids had different sampling occasions and the model ran with error.

Code: Select all
                     ch freq grid
3004  00010000000000000    1    N
3005  00010000000000000    1    N
503   10100000000000000    1    N
522   01000000000000000    1    N
536   00100101000000000    1    N
537   00100100000000000    1    N
539   00110010101000000    1    N
540   00100010000100000    1    N
541   00100010000000000    1    N
543   00100000000100000    1    N
545   00000000100000000    1    N
546   00010001000000000    1    N
547   00010000000000000    1    N
548   00000010000000000    1    N
554   00000000001000101    1    N
555   00000100100000000    1    N
558   00000010000000000    1    N
560   00000010000000000    1    N
570   00000000010000001    1    N
526  110100000100100010    1    S
527  110000000000000000    1    S
528  100001000000000000    1    S
529  010000000000000000    1    S
530  100000000000000000    1    S
531  110000000000000010    1    S
532  001000100010001000    1    S
534  001101110000100001    1    S
542  001000001010000010    1    S
544  000100000000000000    1    S
5451 000100000000100000    1    S
562  000000010000000000    1    S
566  000000000100000000    1    S
568  000000000000000001    1    S
572  000000000000010000    1    S
573  000000000000001000    1    S
577  000000000000010000    1    S
> mark(data,model="HugFullHet", groups="grid", allgroups=TRUE, model.parameters=list(formula=~grid,share=TRUE))

Error in process.data(data, begin.time = begin.time, model = model, mixtures = mixtures,  :
 
Capture history length is not constant. ch must be a character string
 row numbers with incorrect ch length 526,527,528,529,530,531,532,534,542,544,5451,562,566,568,572,573,577


Of course I could run 2 grids separately (which I already did) but it didn't fit my research question. I sampled the study area (with multiple grids) almost concurrently and I think it's more reasonable to estimate N for each grid conditional on the entire population of the study area. Is there away to fix this? If it cannot be done in RMark do I need to go with a BUGS & Bayesian framework instead?

Any comments or suggestions are appreciated. Thanks.

Lamu
Last edited by Triciaserow on Thu Jan 19, 2017 6:27 pm, edited 1 time in total.
Triciaserow
 
Posts: 16
Joined: Tue Oct 20, 2009 11:38 am

Re: Huggins Full Heterogeneity with varying sampling occasio

Postby jlaake » Thu Jan 19, 2017 6:18 pm

First of all, this is not a limitation with RMark but is the way the models are setup in MARK. RMark simply stops you from trying to feed something to MARK that will not work. The solution is to add 0's to the end of the shorter capture histories so they are all the same length. Then create a field called fix in ddl$p and ddl$c and assign it the value NA except for those dummy occasions you added for the grid with the shorter capture histories you'll assign the value 0 to fix. That should do it. See the workshop notes (http://www.phidot.org/software/mark/rmark/RMarkDocumentation.zip)about fixing real parameters for more details.
jlaake
 
Posts: 1417
Joined: Fri May 12, 2006 12:50 pm
Location: Escondido, CA

Re: Huggins Full Heterogeneity with varying sampling occasio

Postby Triciaserow » Thu Jan 19, 2017 10:49 pm

jlaake wrote:First of all, this is not a limitation with RMark but is the way the models are setup in MARK. RMark simply stops you from trying to feed something to MARK that will not work. The solution is to add 0's to the end of the shorter capture histories so they are all the same length. Then create a field called fix in ddl$p and ddl$c and assign it the value NA except for those dummy occasions you added for the grid with the shorter capture histories you'll assign the value 0 to fix. That should do it. See the workshop notes (http://www.phidot.org/software/mark/rmark/RMarkDocumentation.zip)about fixing real parameters for more details.


Thank you, Jeff.

Like this?
Code: Select all
ncol(data.N)
>13
ncol(data.S)
>15
#adding columns to data.N
data.N<-cbind(data.N, matrix(0, nrow(data.N), abs(ncol(data.S)-ncol(data.N))))
#combine data from grid N and S
data<-rbind(data.frame(ch=apply(data.N, 1, paste, collapse=""), grid="N"),
            data.frame(ch=apply(data.S, 1, paste, collapse=""), grid="S"))
data$ch<-as.character(data$ch)
#process and make.design data
pcsdata=process.data(data, model="HugFullHet",groups="grid")
ddl=make.design.data(pcsdata)

ddl$p$fix=ifelse(ddl$p$group=="N"&ddl$p$time%in%c(14,15),0,NA)
ddl$c$fix=ifelse(ddl$c$group=="N"&ddl$c$time%in%c(14,15),0,NA)
ddl
$pi
  par.index model.index group mixture grid
1         1           1     N       1    N
2         2           2     S       1    S

$p
   par.index model.index group time mixture Time grid c fix
1          1           3     N    1       1    0    N 0  NA
2          2           4     N    2       1    1    N 0  NA
3          3           5     N    3       1    2    N 0  NA
4          4           6     N    4       1    3    N 0  NA
5          5           7     N    5       1    4    N 0  NA
6          6           8     N    6       1    5    N 0  NA
7          7           9     N    7       1    6    N 0  NA
8          8          10     N    8       1    7    N 0  NA
9          9          11     N    9       1    8    N 0  NA
10        10          12     N   10       1    9    N 0  NA
11        11          13     N   11       1   10    N 0  NA
12        12          14     N   12       1   11    N 0  NA
13        13          15     N   13       1   12    N 0  NA
14        14          16     N   14       1   13    N 0   0
15        15          17     N   15       1   14    N 0   0
16        16          18     N    1       2    0    N 0  NA
17        17          19     N    2       2    1    N 0  NA
18        18          20     N    3       2    2    N 0  NA
19        19          21     N    4       2    3    N 0  NA
20        20          22     N    5       2    4    N 0  NA
21        21          23     N    6       2    5    N 0  NA
22        22          24     N    7       2    6    N 0  NA
23        23          25     N    8       2    7    N 0  NA
24        24          26     N    9       2    8    N 0  NA
25        25          27     N   10       2    9    N 0  NA
26        26          28     N   11       2   10    N 0  NA
27        27          29     N   12       2   11    N 0  NA
28        28          30     N   13       2   12    N 0  NA
29        29          31     N   14       2   13    N 0   0
30        30          32     N   15       2   14    N 0   0
31        31          33     S    1       1    0    S 0  NA
32        32          34     S    2       1    1    S 0  NA
33        33          35     S    3       1    2    S 0  NA
34        34          36     S    4       1    3    S 0  NA
35        35          37     S    5       1    4    S 0  NA
36        36          38     S    6       1    5    S 0  NA
37        37          39     S    7       1    6    S 0  NA
38        38          40     S    8       1    7    S 0  NA
39        39          41     S    9       1    8    S 0  NA
40        40          42     S   10       1    9    S 0  NA
41        41          43     S   11       1   10    S 0  NA
42        42          44     S   12       1   11    S 0  NA
43        43          45     S   13       1   12    S 0  NA
44        44          46     S   14       1   13    S 0  NA
45        45          47     S   15       1   14    S 0  NA
46        46          48     S    1       2    0    S 0  NA
47        47          49     S    2       2    1    S 0  NA
48        48          50     S    3       2    2    S 0  NA
49        49          51     S    4       2    3    S 0  NA
50        50          52     S    5       2    4    S 0  NA
51        51          53     S    6       2    5    S 0  NA
52        52          54     S    7       2    6    S 0  NA
53        53          55     S    8       2    7    S 0  NA
54        54          56     S    9       2    8    S 0  NA
55        55          57     S   10       2    9    S 0  NA
56        56          58     S   11       2   10    S 0  NA
57        57          59     S   12       2   11    S 0  NA
58        58          60     S   13       2   12    S 0  NA
59        59          61     S   14       2   13    S 0  NA
60        60          62     S   15       2   14    S 0  NA

$c
   par.index model.index group time mixture Time grid c fix
1          1          63     N    2       1    0    N 1  NA
2          2          64     N    3       1    1    N 1  NA
3          3          65     N    4       1    2    N 1  NA
4          4          66     N    5       1    3    N 1  NA
5          5          67     N    6       1    4    N 1  NA
6          6          68     N    7       1    5    N 1  NA
7          7          69     N    8       1    6    N 1  NA
8          8          70     N    9       1    7    N 1  NA
9          9          71     N   10       1    8    N 1  NA
10        10          72     N   11       1    9    N 1  NA
11        11          73     N   12       1   10    N 1  NA
12        12          74     N   13       1   11    N 1  NA
13        13          75     N   14       1   12    N 1   0
14        14          76     N   15       1   13    N 1   0
15        15          77     N    2       2    0    N 1  NA
16        16          78     N    3       2    1    N 1  NA
17        17          79     N    4       2    2    N 1  NA
18        18          80     N    5       2    3    N 1  NA
19        19          81     N    6       2    4    N 1  NA
20        20          82     N    7       2    5    N 1  NA
21        21          83     N    8       2    6    N 1  NA
22        22          84     N    9       2    7    N 1  NA
23        23          85     N   10       2    8    N 1  NA
24        24          86     N   11       2    9    N 1  NA
25        25          87     N   12       2   10    N 1  NA
26        26          88     N   13       2   11    N 1  NA
27        27          89     N   14       2   12    N 1   0
28        28          90     N   15       2   13    N 1   0
29        29          91     S    2       1    0    S 1  NA
30        30          92     S    3       1    1    S 1  NA
31        31          93     S    4       1    2    S 1  NA
32        32          94     S    5       1    3    S 1  NA
33        33          95     S    6       1    4    S 1  NA
34        34          96     S    7       1    5    S 1  NA
35        35          97     S    8       1    6    S 1  NA
36        36          98     S    9       1    7    S 1  NA
37        37          99     S   10       1    8    S 1  NA
38        38         100     S   11       1    9    S 1  NA
39        39         101     S   12       1   10    S 1  NA
40        40         102     S   13       1   11    S 1  NA
41        41         103     S   14       1   12    S 1  NA
42        42         104     S   15       1   13    S 1  NA
43        43         105     S    2       2    0    S 1  NA
44        44         106     S    3       2    1    S 1  NA
45        45         107     S    4       2    2    S 1  NA
46        46         108     S    5       2    3    S 1  NA
47        47         109     S    6       2    4    S 1  NA
48        48         110     S    7       2    5    S 1  NA
49        49         111     S    8       2    6    S 1  NA
50        50         112     S    9       2    7    S 1  NA
51        51         113     S   10       2    8    S 1  NA
52        52         114     S   11       2    9    S 1  NA
53        53         115     S   12       2   10    S 1  NA
54        54         116     S   13       2   11    S 1  NA
55        55         117     S   14       2   12    S 1  NA
56        56         118     S   15       2   13    S 1  NA


I ran this new data and I think it worked. However, I will need to write a function to take care the rest of my data because there were other species on a total of 6 sites. Each site has 2-7 grids. Another coding project. :roll:
Triciaserow
 
Posts: 16
Joined: Tue Oct 20, 2009 11:38 am

Re: Huggins Full Heterogeneity with varying sampling occasio

Postby Triciaserow » Fri Jan 20, 2017 2:20 am

So I tried to write a function which (hopefully) applies to my other species

Everything went smoothly except at the key step of "process.data"

Code: Select all
>df.all
ch Grid
1  00001000000000000 A
2  00001011010000000 A
3  00000010100000000 A
4  00000101000000000 A
5  11111111100000000 A
6  10000000010000000 A
7  00000100000000000 A
8  00000010000000000 A
9  01000010000000000 A
10 00000100000000000 B
11 10000000000000000 B
12 00000100000000000 B
13 00100000000000000 B
14 00001000000000000 B
15 00010000000000000 B
16 01000000000000000 B
17 00001000000000000 C
18 00101011001000000 C
19 00000010100000000 C
20 00000101000000000 C
21 11111111100000000 C
22 10100000001000000 C
23 00000100000000000 C
24 00000010000000000 C
25 01000010000000000 C
26 10000000010000001 C
27 00000000000000001 C
28 01010001001000000 C
29 11011000000010000 C
30 10000110000001010 C
31 12011111011011111 C
32 01000000000100010 C
33 10000000000000000 C
34 00100000000000000 C
35 00000000000010000 C
36 00100000000000100 C
37 00000100100000000 C
38 00000000000100000 C
39 00000010000000000 C
40 10001010000000000 C
41 00000000100000000 C
42 00000010000000000 C
43 00000010000000000 C
44 00000010000000000 C
45 00010010100000000 C
46 00100000000000000 C
47 00001000000000000 C
48 00100010000000000 C
49 00010000000000000 C
50 00000010000000000 C
51 10000000010000001 D
52 01010001001000000 D
53 11011000000010000 D
54 00000000000000001 D
55 10000110000001010 D
56 12011111011011111 D
57 01000000000100010 D
58 00100000000000000 D
59 10000000000000000 D
60 00100000000000000 D
61 00100000000000000 D
62 00000000000010000 D
63 00100000000000100 D
64 00000100100000000 D
65 00000000000100000 D
66 00000010000000000 D
67 10001010000000000 D
68 00000000100000000 D
69 00000010000000000 D
70 00000010000000000 D
71 00000010000000000 D
72 01011000000000000 E
73 10000000000000000 E
74 00100000000000000 E
75 10010000000000000 E
76 01000000000000000 E
77 00010000000000000 E
78 10010000000000000 F
79 10000000000000000 F
80 00001000000000000 F
81 10000000000000000 F
82 01000000000000000 F
83 00100000000000000 F
84 01000000000000000 G
85 00010100000000000 G
86 00101000000000000 G
87 00000010000000000 G
88 10000000000000000 G

Here is the error message
Code: Select all
> pcsdata=process.data(df.all, model="HugFullHet", groups="grid", mixtures=2)
Error in process.data(df.all, model = "HugFullHet", groups = "grid", mixtures = 2) :
 
Incorrect ch values in data:012

Data from other sites showed "incorrect ch values in data:102". But there were only 101 rows in that data set. Didn't quite understand the error message. FYI, function written as below (still at the stage of testing it step-by-step).
Code: Select all
function(keywords, model="HugFullHet"){  #keywords= labels for a species at a site
  # create a list of input objects of multiple grids from a species at a site ("input.spp.site.grid")
  input.ls<-ls(pattern=paste(keywords))
  #get grid name
  grid.ls<-lapply(input.ls, function(x) strsplit(x, split="[.]")[[1]][4])
  #get object
  input.obj<-lapply(input.ls, get)
  #get cap file of each object
  cap.ls<-sapply(input.obj, "[[", "cap")
  #get sampling occassions
  SO.ls<-cap.ls[c("new.SO"),]
  #get maximum sampling occasion of this site
  nocc.max<-max(unlist(lapply(SO.ls, max)))
  #add "0" to those with fewer sampling occassions
  new.cap.ls<-lapply(cap.ls, function(x) cbind(x, matrix(0, nrow(x), nocc.max-ncol(x))))
  # string of indicators to newly added occasions with 0
  na.nocc<-lapply(y2d.ls, function(x) if (ncol(x)<nocc.max) {c((ncol(x)+1):nocc.max)} else {NA})
  #combine all data frame
  df.all<-NULL
  for (i in 1:length(new.y2d.ls)){
    df<-data.frame(ch=apply(new.y2d.ls[[i]], 1, paste, collapse=""), grid=grid.ls[[i]])
    df$ch<-as.character(df$ch)
    df.all<-rbind(df.all, df)
  }
  #process data (not working, got error messages)
  pcsdata=process.data(df.all, model=model, groups="grid", mixtures=2)
  #make design data
  ddl=make.design.data(pcsdata)
  # add column "fix"
  ddl$fix<-NA
  for (i in 1:length(grid.ls)){
    ddl$p$fix[ddl$p$group==grid.ls[[i]]&ddl$p$time%in%na.nocc[[i]]]<-0
    ddl$c$fix[ddl$c$group==grid.ls[[i]]&ddl$c$time%in%na.nocc[[i]]]<-0
  }
  return(list(pcsdata=pcsdata, ddl=ddl))
}
Triciaserow
 
Posts: 16
Joined: Tue Oct 20, 2009 11:38 am

Re: Huggins Full Heterogeneity with varying sampling occasio

Postby jlaake » Fri Jan 20, 2017 9:34 am

It says 012 not 102. It shows the various characters it found in the capture history. 2 is not allowed in this model. Only 0 and 1.
jlaake
 
Posts: 1417
Joined: Fri May 12, 2006 12:50 pm
Location: Escondido, CA

Re: Huggins Full Heterogeneity with varying sampling occasio

Postby Triciaserow » Fri Jan 20, 2017 9:52 am

jlaake wrote:It says 012 not 102. It shows the various characters it found in the capture history. 2 is not allowed in this model. Only 0 and 1.


Yes, I just found that bug because a few individuals were detected twice in some occasions. Thank you so much. Now the function is working just fine.
Triciaserow
 
Posts: 16
Joined: Tue Oct 20, 2009 11:38 am


Return to RMark

Who is online

Users browsing this forum: No registered users and 16 guests