Hi Barnabas,

You can adapt this code, developed by me:

null.model<- function (raster,points,times=1000) {
  r<-as(raster,"SpatialPointsDataFrame")
  ##raster_data.frame<-as.data.frame(raster)
  dist<-numeric(times)
  total<-nrow(points)

  for(i in 1:times) {

    sample<-r[sample(nrow(r),total),1]
    sample_data.frame<-as.data.frame(sample)
    o<-table(sample_data.frame[,1])
    dist[i]<-o[2] /total
    }

  pts<-extract(raster,points,method='simple')
  pts.total<-length(pts)
  x<-table(pts)
  obs<-x[2]/pts.total
  v<-sum(ifelse(dist>=obs,1,0))
  p<-(v+1)/(times+1)
  return(p)
}


[ ]'s!



On Wed, Aug 21, 2013 at 5:44 PM, BARNABAS DARU <darunabas@gmail.com> wrote:

> Dear R members –
> I write to seek help concerning simulation and randomization.
> I have a set equal area grids with observations e.g. phylogenetic
> diversity, per grid.
> I would like to simulate random observations e.g. 1000 times to obtain a
> null distribution of phyogenetic diversity. I will then be glad to know how
> to test the observed patterns against the null to obtain p-values.
> The data is as follows:
>
> grids1  observatn
> g0      71.193510
> g1      110.338347
> g2      155.553859
> g3      178.696210
> g4      139.272733
> g5      120.913020
> g6      112.945412
> g7      106.012243
> g8      80.889829
> g9      95.196947
> g10     182.268465
> g11     195.393473
> g12     198.778229
> g13     177.343460
> g14     167.527703
> g15     167.046954
> g16     169.810604
> g17     166.792720
> g18     139.586739
> g19     138.117178
> g20     129.415400
> …
> Where "grids" are the equal area grids and "observatn" are the observations
>
> Any R code will be greatly appreciated.
> Thanks and kind regards
> Barnabas Daru
>
>
>  \-/
>    /\
>   /--|
>  /---/ Barnabas Daru
>  |--/   PhD Candidate,
>  \-/    African Centre for DNA Barcoding,
>  /\      University of Johannesburg,
> /--\   PO Box 524, Auckland Park, 2006,
> |---\  Johannesburg, South Africa.
>  \---\ Lab: +27 11 559 3477
>   \--|  Mobile: +277 3818 9583
>    \-/  My homepage
>    /\
>   /--\
>
> #…if you can think it, you can do it.
>
>
>
>
>
>
>         [[alternative HTML version deleted]]
>
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
>


-- 
*Me. Ludmila Rattis*
Programa de Pós-graduação em Ecologia/UNICAMP
Conservation Biogeography Lab
http://www.wix.com/rdloyola/lab <http://sites.ffclrp.usp.br/ficus>

	[[alternative HTML version deleted]]

