This is a very short assignment which is meant to... familiar with neighborhood matrices and weights for area data analysis.

advertisement
STAT 406, SPRING 2006
Assignment #6
Due Thursday, March 23, before 10:00 am
This is a very short assignment which is meant to help you become more
familiar with neighborhood matrices and weights for area data analysis.
For the data set Jura posted on the web, you will find the x and y locations in the
first two columns. Besides potential response variables (Cd, Cu, Zn, etc.) there
are several other variables of interest: rock and land use.
For this assignment you are asked to construct a neighborhood matrix
based on whatever criteria you find most appropriate (nearest four, five, six or
some other number neighbors), distance, distance and land use, or any other
criteria that you think would work best. You will create a file that has 100 rows,
on each row you will have the numbers associated with neighboring sites. For
example, if 1 has neighbors 24, 92, 59, 62 and 100, then the first row of your file
would look like:
24 92 59 62 100
Note that not all rows will have the same length, and I suggest you find a
criteria for which each site has at leas one neighbor (this is just to make things
simpler for you in the very beginning). You can do this by hand, I don't expect
you to necessarily write R code for this.
The second task is to create a "weights" matrix. You should do something
very simple: for example, weights are 0 if i and j are not neighbors, 1 if they are.
Again, for the situation described above, where 1 is a neighbor of 24, 92, 59, 62
and 100, the first row of your 100 by 100 weights matrix is:
000000000000000000000001000000000000000000
000000000000000010010000000000000000000000
0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1.
There are many ways of constructing such a matrix in R. Don't try something too
sophisticated for now. Recall that we can define a 100 by 100 matrix of zeroes
as
>w.mat<-matrix(0,100,100)
If you typed w.mat[1,] you would obtain the first row of this matrix. It should
have all zeroes as elements. Now we would like to replace the elements 24, 92,
59, 62 and 100 by ones. An easy way to do this is:
>w.mat[1,c(24,92,59,62,100)]=1
You can do the rest in the same way. I will show you more "automated" ways to
do this in the lab on Thursday.
This is what you need to turn in: a short email explaining the criteria used
for selecting neighbors in no more than 3 lines, in plain English. To this email,
attach two files: the neighborhood selection (call it "your_name_neighb.txt") and
the weights matrix (call it "your_name_weights.txt"). You need to send this to me
before 10 am on Thursday (3/23/06).
To write a file from R into some directory, you can use the command
>write.table(w.mat,
file="your_name_weights.txt",row.names=FALSE,col.names=FALSE)
Although this sounds like a lot of work, I don't expect it will take you more
than two or three hours.
Download