Dear *Adrian Baddeley* ,
  Where is the problem with me?
I run the programs that you provide,but it can't work well, the error
information is as follows:

spatstat 1.9-3

 library(mgcv)
 library(spatstat)
library(graphics)

 edge<-10/3
 SPowin<-rectangle(edge)
*ERROR: no function "rectangle"*
Have i missed somthing?



On 7/6/06, Adrian Baddeley <adrian@maths.uwa.edu.au> wrote:
>
> Dear Zhijie Zhang,
>
> First can I just point out that the calculations you are describing
> could be done much more simply in 'spatstat'.
>
> Instead of
>
> > library(spspatstat)
> > edge <- 10/3
> > crds <- matrix(c(0,0,0,edge,edge,edge,edge,0,0,0), ncol=2, byrow=TRUE)
> > SPoly <- SpatialPolygons(list(Polygons(list(Polygon(crds)), ID=1)))
> > SPowin <- as(SPoly, "owin")
>
> you could just write
>
>    library(spatstat)
>    edge <- 10/3
>    SPowin <- rectangle(edge)
>
> Then after generating the point pattern 'pp', instead of
>
> > nc <- 10  #define the number of grids in rows/columns
> > edge_nc <- edge/nc
> > grd <- GridTopology(c(edge_nc/2, edge_nc/2), c(edge_nc, edge_nc), c(nc,
> nc))
> > SG <- SpatialGrid(grd)
> > ng <- prod(slot(grd, "cells.dim"))
> > SP_MC03 <- as(pp, "SpatialPoints")
> > where <- overlay(SG, SP_MC03)
> > counts <- table(where)  #here,means tables to count the number of points
> in
> > each grid?
> > res <- rep(0, ng)
> > res[as.integer(names(counts))] <- counts
> > SGDF <- SpatialGridDataFrame(grd, data=AttributeList(list(MC03=res)))
> > image(SGDF, "MC03")
>
> you can just write (in spatstat 1.9-3 or later)
>
>    MC03 <- quadratcount(pp, nc)
>    image(MC03)
>
> The object MC03 contains the counts. You can also `plot' and `print' it.
> If you plot it, the counts will be displayed as text. You can extract the
> counts themselves by writing as.matrix(MC03) or as.table(MC03).
>
> But anyway, to answer your question!   %^]
>
> > I hope to control the sample intervals with the numbers of grids,.
> >  E.G. In my dataset , i generated 10*10 grids, the grids maybe coded
> like
> > this(row number, column number)--row(1-10)*col(1-10)grids.  Suppose my
> > systematic sampling is one grid space, then my subset should be
> > row(1,3,5,7,9)*col(1,3,5,7,9)grids=25grids. I think this maybe done by
> > row/column index, but i didn't find it. Anybody has ideas on it? By the
> way,
> > i also want to keep the attributes in my subset.
>
> If I understand correctly, what you want to do is to take a systematic
> sample
> from a matrix (every k-th row and every m-th column, where in your example
> k=2 and m=2).
>
> First convert your count data to a matrix.
>      If you used the 'spatstat' code listed above, just write M <-
> as.matrix(MC03).
>      If you used the 'sp' code in your message, I guess it will be
>      something like M <- as.matrix(SGDF).
>
> Then generate two vectors that specify which rows and which columns
> you sample.
>
>    Suppose you want a sample of every k-th row and every m-th column.
> Then:
>
>    rowphase <- sample(1:k, 1)
>    colphase <- sample(1:m, 1)
>    rowsample <- seq(rowphase, nrow(M), by=k)
>    colsample <- seq(colphase, ncol(M), by=m)
>
> Then take the sample.
>
>     Msample <- M[cbind(rowsample, colsample), drop=FALSE]
>
> The result is a matrix.
>
> [There is actually an undocumented function in spatstat
> called 'matrixsample' which does something similar. In the next version
> of spatstat I will give it some documentation.]
>
> I hope this helps
>
> best wishes
> Adrian Baddeley
>
>
> PS: I will be on holiday for the next 12 days
>
>


-- 
Kind Regards,
Zhi Jie,Zhang ,PHD
Department of Epidemiology
School of Public Health
Fudan University
Tel:86-21-54237149

	[[alternative HTML version deleted]]


