
This happens because you are asking different things.

For example, with  nnwhich(ppp_viz, k=1)  you are 
asking spatstat to find the 1st nearest neighbor of each point in ppp_viz.

On the contrary, with  nnwhich(ppp_viz$marks, 
k=1)  you are asking spatstat to find the 1st 
nearest neighbor of each point in ppp_viz$marks. 
I assume that you are  asking  this by mistake, 
because ppp_viz$marks is not a point pattern but 
a vector of marks, i.e., a factor. What nnwhich 
does in this case is assuming that ppp_viz$marks 
is a numeric vector  (and so each value is a 
point in a line, because there is only one 
dimension) and find the nearest neighbor in the line:

 > as.numeric(ppp_viz$marks)
[1] 5 5 1 4 3 2

 > nnwhich(ppp_viz$marks, k=1)
[1] 2 1 5 5 6 5

i.e., the nn of first element is 2 (i.e. 5); the 
nn of second element is 1 (i.e. 5); the nn of 3st element is 5 (i.e. 2), etc.

Read the help page of nnwhich.


Marcelino



At 20:30 23/11/2010, Kátia Emidio wrote:
>Content-Type: text/plain
>Content-Disposition: inline
>Content-length: 1076
>
>Hi there,
>someone could explain me why the function below   returns different answer
>when I use the line from "nnwhich(ppp_viz$marks..." to just
>"nnwhich(ppp_viz...)"?
>
>
>setwd("")
>require(spatstat)
>require(foreign)
>require(maptools)
>options(digits=22)
>
>x<- c(1,1,2,3,5,7)
>y<-c(1,2,3,3,2,9)
>z<-factor(c("pro heb","pro heb","aba jup","oco cer","Esc cor", "bro rub"))
>wind<-square(10)
>W<-as(wind,"owin")
>#using ppp_viz$marks
>     ppp_viz<-ppp(x,y,window=W, marks= z)
>
>     viz <- vector(length = 4, mode = 'list')
>     for (k in 1:4) viz[[k]] <- nnwhich(ppp_viz$marks, k = k)
>
>     names(viz) <- paste('k', 1:4)
>     str(viz)
>##########without specifying "marks"
>
>viz <- vector(length = 4, mode = 'list')
>     for (k in 1:4) viz[[k]] <- nnwhich(ppp_viz, k = k)
>
>     names(viz) <- paste('k', 1:4)
>     str(viz)
>
>Thanks
>
>--
>Kátia Emídio da Silva DSc
>Eng. Florestal
>Pesquisador
>Embrapa Amazônia Ocidental
>
>Forestry Engineer
>Researcher at Brazilian Agricultural Research Corporation
>  Embrapa western Amazon
>Manaus/AM-Brazil
>
>         [[alternative HTML version deleted]]
>
>
>_______________________________________________
>R-sig-ecology mailing list
>R-sig-ecology@r-project.org
>https://stat.ethz.ch/mailman/listinfo/r-sig-ecology

____________________________________

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

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

