[R-sig-eco] adehabitat conditional MCP creation and export to csv
Mathieu Basille
basille at ase-research.org
Fri Jul 2 15:48:01 CEST 2010
Hakim, you understood perfectly every step of the process (subset,
factor, and mcp). In particular, have a look at ?mcp:
id: a factor giving the identity of the animal for each relocation
Which means that mcp will be computed for each level of 'id'. To make
sure of this, run:
plot(bla) ## where 'bla' is the object in which you stored the mcp
points(q[, c("X", "Y")]
If you just want to compute one single mcp for all individuals (which I
believe is not your aim, otherwise you wouldn't ask to delete all
animals with < 5 relocations), you could do something like that:
mcp(q[, c("X", "Y")], rep("AnyId", nrow(q)), percent = 95)
In any cases, ?mcp is your friend!
Hope this helps,
Mathieu.
Abdi, Abdulhakim a écrit :
> Thanks for your input Mathieu, your example seems to have worked. So, if I understand correctly the following code
>
> subset(p, Name %in% names(which(table(Name) >= 5)))
>
> selects the rows in the data.frame which have 5 or more occurrences under the "Name" column and in order to eradicate the stored levels, the row in question has to be re-encoded as a factor:
>
> q$Name <- factor(q$Name)
>
> I would like to understand the MCP code further:
>
> mcp(q[, c("X", "Y")], q$Name, percent = 95)
>
> by including q$Name into the command you're opting to create separate MCPs for each factor in q$Name?
>
> Again, thank you very much for your assistance, I really appreciate it.
>
> Best,
>
> Hakim Abdi
>
>
>
> _________________________________
> Abdulhakim Abdi, M.Sc.
> Research Intern
>
> Conservation GIS/Remote Sensing Lab
> Smithsonian Conservation Biology Institute
> 1500 Remount Road
> Front Royal, VA 22630
> phone: +1 540 635 6578
> mobile: +1 747 224 7006
> fax: +1 540 635 6506 (Attn:GIS Lab)
> email: abdia at si.edu
> http://nationalzoo.si.edu/SCBI/ConservationGIS/
>
>
>
>
> -----Original Message-----
> From: Mathieu Basille [mailto:basille at ase-research.org]
> Sent: Thursday, July 01, 2010 3:53 PM
> To: Abdi, Abdulhakim
> Cc: r-sig-ecology at r-project.org
> Subject: Re: [R-sig-eco] adehabitat conditional MCP creation and export to csv
>
> Dear Hakim,
>
> The problem comes from Name being a factor. Even if you subset a factor,
> the levels are still stored, so that it gets 0 relocations for some
> individuals. In addition, I'm a little bit perplexed about your 'for'
> loop (especially the if(summary(p$Name)>=5) component).
>
> I would do something like that:
>
> (q <- subset(p, Name %in% names(which(table(Name) >= 5))))
> ## Check:
> table(q$Name)
> q$Name <- factor(q$Name)
> ## Check again:
> table(q$Name) # Now correct
> (bla <- mcp(q[, c("X", "Y")], q$Name, percent = 95))
>
> Hope this helps.
> Mathieu
>
>
> Abdi, Abdulhakim a écrit :
>> Hi everyone,
>>
>> I've searched a few R lists for an answer to this dilemma but it's got me stumped. I have a dataset not unlike the Puechabon dataset that's included with the Adehabitat package:
>>
>>> data(puechabon)
>>> p = puechabon$locs
>>> p = p[-c(94:120,53:90,37:50,7:29),]
>>> p
>> Name Age Sex X Y Date
>> 1 Brock 2 1 699889 3161559 930701
>> 2 Brock 2 1 700046 3161541 930703
>> 3 Brock 2 1 698840 3161033 930706
>> 4 Brock 2 1 699809 3161496 930707
>> 5 Brock 2 1 698627 3160941 930708
>> 6 Brock 2 1 698719 3160989 930709
>> 30 Brock 2 1 699207 3161099 930831
>> 31 Calou 2 1 700098 3161648 930703
>> 32 Calou 2 1 700310 3161323 930704
>> 33 Calou 2 1 699877 3161471 930707
>> 34 Calou 2 1 700003 3161360 930708
>> 35 Calou 2 1 699820 3161387 930709
>> 36 Calou 2 1 699778 3161328 930711
>> 52 Chou 3 2 699640 3158702 920802
>> 53 Chou 3 2 699689 3158857 920803
>> 92 Jean 2 1 699448 3158689 930705
>> 93 Jean 2 1 699500 3158684 930706
>> 94 Jean 2 1 699409 3158794 930707
>>
>> I'm trying to create an MCP for each animal that has 5 or more relocation points (e.g. Brock & Calou) and export each MCP to a CSV file. I've tried the following, but I get an error message:
>>
>>> summary(p$Name)>=5
>> Brock Calou Chou Jean
>> TRUE TRUE FALSE FALSE
>>
>>> for (i in 1:nrow(p)){
>> + if(summary(p$Name)>=5){
>> + mcp.p = mcp(pxy, pid, percent=95)
>> + write.table(mcp.p, sep=",", file=paste(pid,".csv"), col.names=NA)
>> + }
>> + }
>> Error in mcp(pxy, pid, percent = 95) :
>> At least 5 relocations are required to fit an home range
>> In addition: Warning message:
>> In if (summary(p$Name) >= 5) { :
>> the condition has length > 1 and only the first element will be used
>>
>> I'm not an expert in R and would appreciate any help.
>>
>>
>> Regards,
>>
>> _________________________________
>> Hakim Abdi, M.Sc.
>> Research Intern
>>
>> Conservation GIS/Remote Sensing Lab
>> Smithsonian Conservation Biology Institute
>> 1500 Remount Road
>> Front Royal, VA 22630
>> phone: +1 540 635 6578
>> mobile: +1 747 224 7006
>> fax: +1 540 635 6506 (Attn:GIS Lab)
>> email: abdia at si.edu
>> http://nationalzoo.si.edu/SCBI/ConservationGIS/
>>
>> [[alternative HTML version deleted]]
>>
>> _______________________________________________
>> R-sig-ecology mailing list
>> R-sig-ecology at r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
>
--
~$ whoami
Mathieu Basille, Post-Doc
~$ locate
Laboratoire d'Écologie Comportementale et de Conservation de la Faune
+ Centre d'Étude de la Forêt
Département de Biologie
Université Laval, Québec
~$ info
http://ase-research.org/basille
~$ fortune
``If you can't win by reason, go for volume.''
Calvin, by Bill Watterson.
More information about the R-sig-ecology
mailing list