Multiple groups with unequal numbers

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

Multiple groups with unequal numbers

Postby jenmarie2478 » Thu Jan 10, 2013 9:13 pm

I am trying to input a file with 4 encounter histories and two separate groups (5 transects and 4 years). I've tried different variations of code (below) but I always get an error that the number or rows or groups doesn't match. I think I am having the problem since there are FIVE transects and FOUR years, i.e. they are unequal. All of the examples in the workshop and help files are of even numbers of two groups (2 and 2).

Any suggestions would be most appreciated. I'm sure it will be an easy fix that I just can not see at the moment.

sihispring<-convert.inp("C:/sihi_spring_new.inp",group.df=data.frame(transect=c(rep("1","2","3","4","5"),4),Year=rep(c("2009","2010","2011","2012"),5)))

or

sihispring<-convert.inp("C:/sihi_spring_new.inp",group.df=data.frame(transect=rep(c("1","2","3","4","5"),4),Year=rep(c("2009","2010","2011","2012"),5)))

or

sihispring<-convert.inp("C:/sihi_spring_new.inp",group.df=data.frame(transect=c("1","2","3","4","5"),year=c("2009","2010","2011","2012")))


My original input looked like this:


/* SIHI 1 2009 SIHI1 */ 1000 1 0 0 0 0 1 0 0 0;
/* SIHI 1 2009 SIHI15 */ 0010 1 0 0 0 0 1 0 0 0;
/* SIHI 1 2009 SIHI16 */ 0010 1 0 0 0 0 1 0 0 0;
/* SIHI 1 2009 DEAD2 */ 001- 1 0 0 0 0 1 0 0 0;
/* SIHI 2 2009 SIHI2 */ 1000 0 1 0 0 0 1 0 0 0;
etc....


But then just in case my comments were messing it up, I reformatted to this:

1000 1 0 0 0 0 1 0 0 0 ;
0010 1 0 0 0 0 1 0 0 0 ;
0010 1 0 0 0 0 1 0 0 0 ;
001- 1 0 0 0 0 1 0 0 0 ;
1000 0 1 0 0 0 1 0 0 0 ;
etc....
jenmarie2478
 
Posts: 4
Joined: Thu Jan 10, 2013 8:49 pm

Re: Multiple groups with unequal numbers

Postby jlaake » Fri Jan 11, 2013 1:47 pm

A few clarifications. I think you meant 4 occasions and not 4 encounter histories. Were the 5 transects each run in the 4 years? If so, your group file should have had 20 entries and not 9. That is the problem you are encountering trying to read in the data. It is expecting each combination which is the way it should have been constructed for MARK. Were these data originally in MARK? If not, then you could have used the RMark format of

ch transect year
1001 1 1
0011 1 2
etc

and read it in with read.table or import.chdata.

--jeff
jlaake
 
Posts: 1480
Joined: Fri May 12, 2006 12:50 pm
Location: Escondido, CA

Re: Multiple groups with unequal numbers

Postby jenmarie2478 » Fri Jan 11, 2013 2:11 pm

Yes, the data was originally in MARK, and actually it was in the format with 20 columns. I started second guessing myself yesterday on how I would get both groups in so that they could be tested against each other.

This was how the data was originally:

/* SIHI 1 2010 1720 */ 1011 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
/* SIHI 1 2010 1729 */ 0011 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
/* SIHI 1 2011 350 */ 1000 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0;
/* SIHI 1 2011 387 */ 1010 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0;
/* SIHI 1 2011 64 */ 1100 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0;
/* SIHI 1 2011 112 */ 1000 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0;

The group columns are 2009transect1, 2009T2, 2009T3, 2009T4, 2009T5, 2010T1, etc...

But now that they are combined, with each column being a year and a transect, I guess I'm getting myself confused on how to test year*transect interactions.

So with the original data above, the input code would be:

sihispring<-convert.inp("C:/sihi_spring_new.inp",group.df=data.frame(transect=rep(c("1","2","3","4","5"),4),Year=rep(c("2009","2010","2011","2012"),5)))

Correct?
jenmarie2478
 
Posts: 4
Joined: Thu Jan 10, 2013 8:49 pm

Re: Multiple groups with unequal numbers

Postby jlaake » Fri Jan 11, 2013 2:18 pm

You are close. What you need to learn to do with R is to pull apart the syntax to look at each piece.

Below is what you have specified:
Code: Select all
 > data.frame(transect=rep(c("1","2","3","4","5"),4),Year=rep(c("2009","2010","2011","2012"),5))
   transect Year
1         1 2009
2         2 2010
3         3 2011
4         4 2012
5         5 2009
6         1 2010
7         2 2011
8         3 2012
9         4 2009
10        5 2010
11        1 2011
12        2 2012
13        3 2009
14        4 2010
15        5 2011
16        1 2012
17        2 2009
18        3 2010
19        4 2011
20        5 2012


which you can see is not in the correct order. What you need is:

Code: Select all
data.frame(transect=rep(c("1","2","3","4","5"),4),Year=rep(c("2009","2010","2011","2012"),each=5))
   transect Year
1         1 2009
2         2 2009
3         3 2009
4         4 2009
5         5 2009
6         1 2010
7         2 2010
8         3 2010
9         4 2010
10        5 2010
11        1 2011
12        2 2011
13        3 2011
14        4 2011
15        5 2011
16        1 2012
17        2 2012
18        3 2012
19        4 2012
20        5 2012


When you use the process.data step, specify groups=c("transect","Year") and you'll be able to fit group models

~Year
~transect
~transect+Year
~transect*Year

and any others you need.

--jeff
jlaake
 
Posts: 1480
Joined: Fri May 12, 2006 12:50 pm
Location: Escondido, CA

Re: Multiple groups with unequal numbers

Postby jenmarie2478 » Sat Jan 12, 2013 6:27 pm

Thank you so much! That "each" code was what I was missing. It has been a while since I've used R so it's a little bit of re-learning.

Now I'm having the issue of some of my seasons I have 4 transects in 2009, then 5 in 2010 through 2012.

I have tried multiple combinations, such as:

(transect=rep(c("1","2","3","4"),1 (1","2","3","4","5"),3),year=rep(c("2009",each=4,"2010","2011","2012",each=5)))

(transect=c("1","2","3","4"),rep(1","2","3","4","5"),3),year=rep(c("2009"),each=4,("2010","2011","2012"),each=5)))

And many more...

I even tried simply writing out all the transect numbers and years as a string without using the repeat function and no go yet.

I've tried it with all sorts of variations with or without parentheses or commas. Just when I think I've gotten it I'll get a new error.

I want to end up with
1 2009
2 2009
3 2009
4 2009
1 2010
2 2010
3 2010
4 2010
5 2010
then so on with 5 transects


Thank you again for any help!
jenmarie2478
 
Posts: 4
Joined: Thu Jan 10, 2013 8:49 pm

Re: Multiple groups with unequal numbers

Postby jlaake » Sat Jan 12, 2013 7:00 pm

Is this what you want? Note that if you can't figure it out you could have always listed out each set or read into a database from a file. --jeff

data.frame(transect=c(1:4,rep(1:5,3)),year=c(rep(2009,4),rep(2010:2012,each=5)))
transect year
1 1 2009
2 2 2009
3 3 2009
4 4 2009
5 1 2010
6 2 2010
7 3 2010
8 4 2010
9 5 2010
10 1 2011
11 2 2011
12 3 2011
13 4 2011
14 5 2011
15 1 2012
16 2 2012
17 3 2012
18 4 2012
19 5 2012
>
jlaake
 
Posts: 1480
Joined: Fri May 12, 2006 12:50 pm
Location: Escondido, CA


Return to RMark

Who is online

Users browsing this forum: No registered users and 0 guests