Dear R users I'm trying to reproduce the results from Lowry et al. 2007 Lunar landings - Relationship between lunar phase and catch rates for an Australian gamefish-tournament fisheryFisheries Research 88: 15?23 Basically we have two columns: Lunar days and CPUE (catch per unit effort). The aim is to test whether CPUE varies with the lunar cycle Here is what I did: library(circular) # Black marlin CPUE U<-c(0.02,0.024,0.017,0.02,0.018,0.034,0.042,0.026,0.017,0.019,0.006,0.008,0.011,0.014,0.007,0.018,0.008,0.004,0.008,0.013,0.011,0.008,0.006,0.004,0.008,0.005,0.016,0.011,0.022,0.048) # Lunar day LD <- seq(1:30) # Lunar Day in radians LDrad <- (360*LD)/29.58 # Plots plot(U~LD) plot(U~LDrad) # Transform LDcir <- circular(U,LDrad,type=c("angles"),units=c("radians")) # circular model circ.lm<-lm.circular(y=U,x=LDcir,init=1,type="c-l",verbose=TRUE) but it runs with circ.lm<-lm.circular(x=U,y=LDcir,init=1,type="c-l",verbose=TRUE) Nevertheless U must be the dependent variable, not the independent one. I also tried Uy <- cbind(U,rep(1,length(U))) circ.lm<-lm.circular(y=Uy,x=LDcir,init=2,type="c-l",verbose=TRUE) Well I really appreciate any help, thanks in advance, Antonio Olinto [[alternative HTML version deleted]]
John Sorkin
2015-Oct-24 22:28 UTC
[R] Add sequence numbers to lines with the same ID: How can this be accomplished?
I have a file that has (1) Line numbers, (2) IDs. A given ID number can appear in more than one row. For each row with a repeated ID, I want to add a number that gives the sequence number of the repeated ID number. The R code below demonstrates what I want to have, without any attempt to produce the result, as I have no idea how to accomplish my goal. line <- c(1,2,3,4,5,6,7,8,9,10) ID<- c(1,1,2,3,4,5,6,7,8,8) cat("Note lines 1 and 2 both contain ID 1; lines 9 and 10 both contain ID 8") cbind(line,ID) Seq <- c(1,2,1,1,1,1,1,1,1,2) cat("Sequence numbers within ID added to the data") cbind(line,ID,Seq) John David Sorkin M.D., Ph.D. Professor of Medicine Chief, Biostatistics and Informatics University of Maryland School of Medicine Division of Gerontology and Geriatric Medicine Baltimore VA Medical Center 10 North Greene Street GRECC (BT/18/GR) Baltimore, MD 21201-1524 (Phone) 410-605-7119 (Fax) 410-605-7913 (Please call phone number above prior to faxing) Confidentiality Statement: This email message, including any attachments, is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message.
Rolf Turner
2015-Oct-24 23:02 UTC
[R] Add sequence numbers to lines with the same ID: How can this be accomplished?
On 25/10/15 11:28, John Sorkin wrote:> I have a file that has (1) Line numbers, (2) IDs. A given ID number can appear in more than one row. For each row with a repeated ID, I want to add a number that gives the sequence number of the repeated ID number. The R code below demonstrates what I want to have, without any attempt to produce the result, as I have no idea how to accomplish my goal. > > > line <- c(1,2,3,4,5,6,7,8,9,10) > ID<- c(1,1,2,3,4,5,6,7,8,8) > cat("Note lines 1 and 2 both contain ID 1; lines 9 and 10 both contain ID 8") > cbind(line,ID) > Seq <- c(1,2,1,1,1,1,1,1,1,2) > cat("Sequence numbers within ID added to the data") > cbind(line,ID,Seq)I *think* that unlist(lapply(rle(ID)$lengths,seq_len)) gives what you want. At least it does for the given example. cheers, Rolf Turner -- Technical Editor ANZJS Department of Statistics University of Auckland Phone: +64-9-373-7599 ext. 88276
Reading the help page with attention I saw that this function fits a regression model for "circular dependent and linear independent". So my question now is, is there a way to fit a model been with the circular as the dependent variable? Thanks Antonio 2015-10-24 20:19 GMT-02:00 Antonio Silva <aolinto.lst at gmail.com>:> Dear R users > > I'm trying to reproduce the results from Lowry et al. 2007 Lunar landings > - Relationship between lunar phase and catch rates for an Australian > gamefish-tournament fisheryFisheries Research 88: 15?23 > > Basically we have two columns: Lunar days and CPUE (catch per unit > effort). The aim is to test whether CPUE varies with the lunar cycle > > Here is what I did: > > library(circular) > # Black marlin CPUE > > U<-c(0.02,0.024,0.017,0.02,0.018,0.034,0.042,0.026,0.017,0.019,0.006,0.008,0.011,0.014,0.007,0.018,0.008,0.004,0.008,0.013,0.011,0.008,0.006,0.004,0.008,0.005,0.016,0.011,0.022,0.048) > # Lunar day > LD <- seq(1:30) > # Lunar Day in radians > LDrad <- (360*LD)/29.58 > # Plots > plot(U~LD) > plot(U~LDrad) > # Transform > LDcir <- circular(U,LDrad,type=c("angles"),units=c("radians")) > # circular model > circ.lm<-lm.circular(y=U,x=LDcir,init=1,type="c-l",verbose=TRUE) > > but it runs with > circ.lm<-lm.circular(x=U,y=LDcir,init=1,type="c-l",verbose=TRUE) > > Nevertheless U must be the dependent variable, not the independent one. > > I also tried > > Uy <- cbind(U,rep(1,length(U))) > circ.lm<-lm.circular(y=Uy,x=LDcir,init=2,type="c-l",verbose=TRUE) > > Well I really appreciate any help, thanks in advance, > > Antonio Olinto >-- Ant?nio Olinto ?vila da Silva Bi?logo / Ocean?grafo Instituto de Pesca (Fisheries Institute) S?o Paulo, Brasil [[alternative HTML version deleted]]