<div>Dear Roger Bivand and Dan Putler,</div>
<div> The result is really good, and i'm also clear with the choice of sigma in density.ppp() function.</div>
<div> I still have another two little problems:</div>
<div><strong><font color="#ff0000">Q1</font></strong>: How to change the background color into other color(e.g. white),or specify all the colors into the user-defined colors?</div>
<div>myPal=brewer.pal(4,"Paired") # For example, how to specify the 4 colors with white,black,red,and blue.</div>
<div>I'm not familiar with RColorBrewer package, but i need it now. I'm now learning it.</div>
<div><br><strong><font color="#ff0000">Q2</font></strong>: How to overlay the other .shp file with the result of kernel density estimation?<br>The other .shp file is Qiupu River and Yangtze River. If i can overlay them with the result of kernel density estimation,
<br> it'll be very clear that the cross part of Qiupu River and Yangtze River has the highest density,which is true in reality and really<br> what i want.</div>
<div> Thanks very much.</div>
<div><br><br><br> </div>
<div><span class="gmail_quote">On 6/26/07, <b class="gmail_sendername">Roger Bivand</b> <<a href="mailto:Roger.Bivand@nhh.no">Roger.Bivand@nhh.no</a>> wrote:</span>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">On Mon, 25 Jun 2007, Dan Putler wrote:<br><br>Thanks, Dan, I agree that the bandwidths are the problem here. Often the
<br>image breaks settings are also very misleading for 2D density plots, so<br>one needs to take care, as you show.<br><br>Roger<br><br>> Hi Zhi Jie,<br><br>Below are some changes to your code which should make you much
<br>happier. It does involve the use of the RColorBrewer package to<br>create a color palette that makes the plot a bit easier to see. As<br>you can guess, the size of the standard deviation given to<br>density.ppp was the problem. Your data is in the Xian 1980/3-degree
<br>Gauss-Kruger CM 117E projection (which is EPSG code 2384). Based on<br>looking at things, the units of this projection are meters. Using the<br>defaults of density.ppp, the standard deviation of the bandwidth of<br>the smoother is
0.05 meters, far smaller than you wanted. The<br>implicit assumption in density.ppp appears to be that the window of<br>the study area is a unit square. The width of your study area is<br>about 60Km, so to get a comparable bandwidth for your study area
<br>relative to the unit square, I upped the standard deviation to 3000<br>meters.<br><br>Here is my altered version of your code, you will need to change<br>things back to the correct paths to the shapefile sets.<br>________
<br>library(spatstat)<br>library(maptools)<br>library(RColorBrewer)<br><br>myPal=brewer.pal(12,"Paired") # An easily seen color palette<br><br>guichi<-readShapePoly("~/Research/data/guichi2.shp")<br>
W <-as(as(guichi, "SpatialPolygons"), "owin") #boundary polygons<br><br>cases<-coordinates(readShapePoints("~/Research/data/cases.shp"))<br>#points<br>colnames(cases)<-c("x","y")
<br>cases[1:2,]<br><br>#plot(W);points(cases)<br><br>pointcase <- ppp(cases[,1], cases[,2], window=W) #generate the ppp<br>object<br><br>kdensity<-density.ppp(pointcase, 3000)<br>plot(kdensity, col=myPal)<br><br>rm(list=c("guichi","W","cases","pointcase","kdensity","myPal"))
<br>_______<br><br>Dan<br><br>On 25-Jun-07, at 7:49 AM, zhijie zhang wrote:<br><br>> Dear Roger Bivand,Tim Keitt, and Dan Putler,<br>> Thanks for your answers. I have tried density.ppp(spatstat) and<br>> kernel2d(splancs), but the results are not very satisfied. I think
<br>> there should be a higher density in the blue part of the map in the<br>> attachment.<br>> My dataset has been put in the attachment and programs have been<br>> pasted in the following, so that u can use and check it.
<br>> I want to do the work like "non-parametric estimation of a<br>> spatially varying intensity" in Diggle's book(2003.P.116-121).<br>> BTW, i'm not familiar with locfit,would u please also check it
<br>> using locfit? Thanks very much.<br>> ######################################################################<br>> #########<br>> Kernel density estimation--spatstat<br>> ######################################################################
<br>> ##########<br>> library(sp)<br>> library(foreign)<br>> library(maptools)<br>> library(mgcv)<br>> library(spatstat)<br>> guichi<-readShapePoly("d:/deleting/kernel/kernel/guichi2.shp")
<br>> W <-as(as(guichi, "SpatialPolygons"), "owin") #boundary polygons<br>><br>> cases<-coordinates(readShapePoints("d:/deleting/kernel/kernel/<br>> cases.shp")) #points<br>
> colnames(cases)<-c("x","y")<br>> cases[1:2,]<br>><br>> #plot(W);points(cases)<br>><br>> pointcase <- ppp(cases[,1], cases[,2], window=W) #generate the ppp<br>> object<br>>
<br>> kdensity<-density.ppp(pointcase, 0.05)<br>> plot(kdensity)<br>> Q:there are almost the same density in the whole area,but in fact<br>> it may have a higher density in the blue part of the attached map?
<br>> I think the problem may the inappropriate value of sigma, how to<br>> determine its value?<br>><br>> ######################################################################<br>> ##########<br>> Kernel density estimation--splancs
<br>> ######################################################################<br>> ##########<br>> library(sp)<br>> library(splancs)<br>> library(foreign)<br>> library(maptools)<br>><br>> case<-readShapePoints("d:/deleting/kernel/kernel/cases.shp")
<br>> guichi<-readShapePoly("d:/deleting/kernel/kernel/guichi2.shp")<br>><br>> #Conversion<br>> case_pts <- coordinates(case)<br>> case <- as.points(case_pts)<br>> splancs_poly <- getPolygonCoordsSlot(getPolygonsPolygonsSlot
<br>> (getSpPpolygonsSlot(guichi)[[1]])[[1]])<br>><br>> #to unpack the coordinates of the points and the single ring boundary<br>> polymap(splancs_poly,xlab="x(ÿÿ)",ylab="y(ÿÿ)")<br>> pointmap(case_pts, add=TRUE)
<br>><br>> m<-mse2d(case,splancs_poly,nsmse=1000,range=5) #plots the<br>> estimated mean square error as a function of h0<br>> plot(m$h[290:1000],m$mse[290:1000],type="l")<br>><br>> n<-which(m$mse==min(m$mse))
<br>> h0<-m$h[n]<br>><br>><br>> #smooth variation<br>> smooth<-kernel2d(case, splancs_poly, h0=h0, nx=100, ny=100)<br>> polymap(splancs_poly) #sets the axes correctly and draws the polygon<br>> image(smooth,add=T) #the smoothed image is superimposed
<br>> polymap(splancs_poly,add=T) #redrawn the polymap in order not to be<br>> obsured by smooth image<br>> Q:The result is still not satisfied,there must be something wrong<br>> with my programs .<br>><br>
><br>><br>><br>><br>><br>> On 6/25/07, Dan Putler <<a href="mailto:putler@sauder.ubc.ca">putler@sauder.ubc.ca</a>> wrote: Hi All,<br>><br>> To add some detail to Roger's earlier, post density.ppp
in the<br>> spatstat seems to be a very good answer to the original post since it<br>> is specifically designed to estimate a kernel density for a point<br>> process pattern. This function use a bivariate Gaussian smoother that
<br>> lends itself to user configuration.<br>><br>> Dan<br>><br>> On 24-Jun-07, at 5:28 PM, Tim Keitt wrote:<br>><br>> > I rather like locfit.<br>> ><br>> > THK<br>> ><br>> > On 6/24/07, zhijie zhang <
<a href="mailto:epistat@gmail.com">epistat@gmail.com</a>> wrote:<br>> >> Dear Friends,<br>> >> Except kernel2d(splancs) function, are there any other functions<br>> >> on kernel<br>> >> density estimation in point pattern analysis? I use the kernel2d
<br>> >> (splancs)<br>> >> function to anayze my dataset, and the result seems not to be very<br>> >> good.<br>> >> Any suggestions or help in kernel density estimation of<br>> >> univariate or
<br>> >> multivariate point process are greatly appreciated.<br>> >> BTW, i mainly want ot do the kernel density estimation in both<br>> >> univariate and multivariate point process.<br>> >> --
<br>> >> With Kind Regards,<br>> >><br>> >> oooO:::::::::<br>> >> (..):::::::::<br>> >> :\.(:::Oooo::<br>> >> ::\_)::(..)::<br>> >> :::::::)./:::<br>> >> ::::::(_/::::
<br>> >> :::::::::::::<br>> >><br>> [********************************************************************<br>> >> ***]<br>> >> Zhi Jie,Zhang ,PHD<br>> >> Tel:86-21-54237149<br>
> >> Dept. of Epidemiology,School of Public Health,Fudan University<br>> >> Address:No. 138 Yi Xue Yuan Road,Shanghai,China<br>> >> Postcode:200032<br>> >> <a href="mailto:Email:epistat@gmail.com">
Email:epistat@gmail.com</a><br>> >> Website: <a href="http://www.statABC.com">www.statABC.com</a><br>> >><br>> [********************************************************************<br>> >> ***]
<br>> >> oooO:::::::::<br>> >> (..):::::::::<br>> >> :\.(:::Oooo::<br>> >> ::\_)::(..)::<br>> >> :::::::)./:::<br>> >> ::::::(_/::::<br>> >> :::::::::::::<br>
> >><br>> >> [[alternative HTML version deleted]]<br>> >><br>> >> _______________________________________________<br>> >> R-sig-Geo mailing list<br>> >> <a href="mailto:R-sig-Geo@stat.math.ethz.ch">
R-sig-Geo@stat.math.ethz.ch</a><br>> >> <a href="https://stat.ethz.ch/mailman/listinfo/r-sig-geo">https://stat.ethz.ch/mailman/listinfo/r-sig-geo</a><br>> >><br>> ><br>> ><br>> > --<br>
> > Timothy H. Keitt, University of Texas at Austin<br>> > Contact info and schedule at <a href="http://www.keittlab.org/tkeitt/">http://www.keittlab.org/tkeitt/</a><br>> > Reprints at <a href="http://www.keittlab.org/tkeitt/papers/">
http://www.keittlab.org/tkeitt/papers/</a><br>> > ODF attachment? See <a href="http://www.openoffice.org/">http://www.openoffice.org/</a><br>> ><br>> > _______________________________________________<br>
> > R-sig-Geo mailing list<br>> > <a href="mailto:R-sig-Geo@stat.math.ethz.ch">R-sig-Geo@stat.math.ethz.ch</a><br>> > <a href="https://stat.ethz.ch/mailman/listinfo/r-sig-geo">https://stat.ethz.ch/mailman/listinfo/r-sig-geo
</a><br>><br>><br>><br>><br>> --<br>> With Kind Regards,<br>><br>> oooO:::::::::<br>> (..):::::::::<br>> :\.(:::Oooo::<br>> ::\_)::(..)::<br>> :::::::)./:::<br>> ::::::(_/::::<br>> :::::::::::::
<br>> [*********************************************************************<br>> **]<br>> Zhi Jie,Zhang ,PHD<br>> Tel:86-21-54237149<br>> Dept. of Epidemiology,School of Public Health,Fudan University<br>> Address:No. 138 Yi Xue Yuan Road,Shanghai,China
<br>> Postcode:200032<br>> <a href="mailto:Email:epistat@gmail.com">Email:epistat@gmail.com</a><br>> Website: <a href="http://www.statABC.com">www.statABC.com</a><br>> [*********************************************************************
<br>> **]<br>> oooO:::::::::<br>> (..):::::::::<br>> :\.(:::Oooo::<br>> ::\_)::(..)::<br>> :::::::)./:::<br>> ::::::(_/::::<br>> :::::::::::::<br>> <data.rar><br>> <map.jpg><br><br>
_______________________________________________<br>R-sig-Geo mailing list<br><a href="mailto:R-sig-Geo@stat.math.ethz.ch">R-sig-Geo@stat.math.ethz.ch</a><br><a href="https://stat.ethz.ch/mailman/listinfo/r-sig-geo">https://stat.ethz.ch/mailman/listinfo/r-sig-geo
</a><br><br>--<br>Roger Bivand<br>Economic Geography Section, Department of Economics, Norwegian School of<br>Economics and Business Administration, Helleveien 30, N-5045 Bergen,<br>Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
<br>e-mail: <a href="mailto:Roger.Bivand@nhh.no">Roger.Bivand@nhh.no</a><br></blockquote></div><br><br clear="all"><br>-- <br>With Kind Regards,<br><br>oooO:::::::::<br>(..):::::::::
<br>:\.(:::Oooo:: <br>::\_)::(..):: <br>:::::::)./::: <br>::::::(_/:::: <br>:::::::::::::<br>[***********************************************************************]
<br>Zhi Jie,Zhang ,PHD <br>Tel:86-21-54237149 <br>Dept. of Epidemiology,School of Public Health,Fudan University <br>Address:No. 138 Yi Xue Yuan Road,Shanghai,China <br>Postcode:200032 <br><a href="mailto:Email:epistat@gmail.com">
Email:epistat@gmail.com</a> <br>Website: <a href="http://www.statABC.com">www.statABC.com</a><br>[***********************************************************************]<br>oooO:::::::::<br>(..):::::::::
<br>:\.(:::Oooo:: <br>::\_)::(..):: <br>:::::::)./::: <br>::::::(_/:::: <br>:::::::::::::