[R-sig-Geo] how to get my subset?
Roger Bivand
Roger.Bivand at nhh.no
Sun Apr 9 20:04:16 CEST 2006
On Sun, 9 Apr 2006, zhijie zhang wrote:
> Dear friends,
> I want to do some simulations on Moran's I, but met some problems with
> subset my dataset:
>
> First step: generate my dataset
> *x<-rnorm(20)* # generate my attribute data
> *y<-cell2nb(4,5)* # generate my neighbor object
> Then my dataset comprise with x(attribute data) and y(position).
>
> Second step:subset my datset
> I don't have any idea on how to get my subset, which is from two different
> sampling on my generated data:
> 1.random sampling: sample 4 data randomly from my generated data;
x<-rnorm(20)
y<-cell2nb(4,5)
s1 <- sample(1:length(x), 4)
x_s1 <- x[s1]
y_s1 <- subset(y, 1:length(x) %in% s1)
(but with such a small sample, very few neighbour links will remain)
> 2.systematic sampling: Suppose the space is 1, the the subset should be like
> the following:
> y:1 3rows,1 3 5colums
> x: the correspding attribute data
look at attr(y, "region.id") to choose the subset, do:
rc <- do.call("rbind", strsplit(attr(y, "region.id"), ":"))
to extract the IDs as a character row, column matrix.
I'm not sure why sampling is useful here, simulations on Moran's I are
usually done by permutations on the x values, for example by
permutation bootstrap. There are examples among other places in
the DCluster and spdep packages, in spdep in the example to function
moran.mc().
> I thought it maybe need to use index to get it , or some other better
> methods. I still can't get it through till now, could anybody help me?
> Any suggestions or help would be greatly appreciated1
> --
> Kind Regards,Zhi Jie,Zhang ,PHD
> Department of EpidemiologySchool of Public HealthFudan
> UniversityTel:86-21-54237149
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
--
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no
More information about the R-sig-Geo
mailing list