Hi Aurelie,

I think that your problem is that you dont use the argument 
"savefuns=TRUE", so LF.gof can't find the simulated functions to 
compute the test.

In any case, I realized that I have send a preliminary version of the 
code without correcting some mistakes (that would show when selecting 
distance ranges to compute the test).

Here below is the corrected version

Best wishes,

Marcelino



##########################################################################################

LF.gof<- function(X, rmin=NULL, rmax=NULL){
    require(spatstat)

    # controls that is using an envelope object and that it has been 
computed with the argument savefuns=TRUE
     if(sum(!is.na(match(class(X),"envelope")))==0) stop("LF.gof only 
accept spatstat envelope objects")
     if(is.null(attributes(X)$simfuns)) stop ("did you compute the 
envelopes with the argument 'savefuns=TRUE'?")

     # get data
     r <- as.data.frame(attributes(X)$simfuns)[,1]
     H1 <- X$obs
     Hi <- as.data.frame(attributes(X)$simfuns)[,-1]

     #Join observed and simulated functions
     H <- cbind(H1,Hi)

     # select the range of integrable results
     if (!is.null(rmin) & !is.null(rmax)){ H <- H[r >= rmin & r <= rmax,]}
     if (!is.null(rmin) & is.null(rmax)) { H <- H[r >= rmin,]}
     if (is.null(rmin) & !is.null(rmax)) { H <- H[r <= rmax,]}

     s <- dim(H)[2]

     # compute summary statistics for the observed (i.e., first) pattern
     Hmeans <- rowSums (H[,-1],  na.rm = FALSE)/(s-1)
     u <- sum((H[,1]-Hmeans)^2)

      # compute summary statistics for the simulated patterns
      for ( i in 2:s) {
          Himeans <- rowSums (H[,-i])/(s-1)
          u <- c(u, sum((H[,i]-Himeans)^2))
        }
      p <-  1-((rank(u)[1]-1)/(s))

return(list(u=u[1], p=p))
}


########################################################################################








At 16:08 02/03/2012, Aurelie C.Godin wrote:
>Thank you Marcelino!
>
>You are right, I am trying to test the random labelling hypothesis instead
>of CSR.
>I've been able to run your LF.gof with the nztrees dataset, however, when I
>test the envelope with the simulated rlabel list and run the LF.gof I get an
>error message:
>http://r-sig-geo.2731867.n2.nabble.com/file/n7336880/OTGR.RData OTGR.RData
>
> > LF.gof(GR.env)
>Error in `[.data.frame`(as.data.frame(attributes(X)$simfuns), , 1) :
>   undefined columns selected
>
>I've also tried the following coding for which I still get the same error
>message.
>
># Precomputed list of point patterns
>OTim<-as.im(OT)#create a pixel image of the point pattern of all my events
>(OT)
># Simulate GR$n random point patterns within OTim
>Xlist <- list()
>for (i in 1:198) Xlist[[i]] <-  rpoint(563,OTim)
>#compute the envelope
>EE<-envelope(GR,Kest,simulate=Xlist)
> > LF.gof(EE)
>Error in `[.data.frame`(as.data.frame(attributes(X)$simfuns), , 1) :
>   undefined columns selected
>
>I thought that the above code would give me a similar result then your code,
>but I do get quiet different plots. Is this simply because of the pixel
>image? Or is there something else here that I'm missing?
>
>Any ideas of what can cause this error message?
>Thank you very much,
>
>
>-----
>Aurelie Cosandey-Godin
>Ph.D. Student, Department of Biology, Dalhousie University
>Industrial Graduate Fellow, WWF-Canada
>Email: godina@dal.ca | Web: wormlab.biology.dal.ca
>
>--
>View this message in context: 
>http://r-sig-geo.2731867.n2.nabble.com/Loosmore-and-Ford-2006-Goodness-of-fit-GoF-test-for-CSR-tp7332928p7336880.html
>Sent from the R-sig-geo mailing list archive at Nabble.com.
>
>_______________________________________________
>R-sig-Geo mailing list
>R-sig-Geo@r-project.org
>https://stat.ethz.ch/mailman/listinfo/r-sig-geo

____________________________________

Marcelino de la Cruz Rot
Depto. Biologia Vegetal
EUIT Agricola
Universidad Politecnica de Madrid

tel: 34 + 913365435
____________________________________  
	[[alternative HTML version deleted]]

