By following these instructions from Thomas I have created a ppp object using the spatstat package in R.
Because my data set includes a time dimension, I want to expand this analysis to consider the 3D space-time for clustering analysis.
The SPATSTAT VERSION 2 Preliminary Announcement 6th revision, dated 9th February 2010, suggests this should be possible with the new R package spatstat2. The announcement says:
The new class pp of point patterns will support:
multiple marks attached to each point
(e.g. trees can be marked by their species, diameter at breast height and leaf toxicity assay).
point patterns in different spaces, including 3D points, 2D space-time, 3D space-time, 1D networks in 2D space, different distance metrics
marks of ANY type
(each mark can be a window, a point pattern, a function etc etc)
However, beyond the announcement, I cannot find many additional details about the anticipated spatstat2 package. And I also cannot install the package from CRAN:
package ‘spatstat2’ is not available (for R version 3.0.3)
My questions are:
what are the best methods available in R for clustering analysis of events data (each event with geospatial coordinates X, Y, plus a Timestamp) ?
what has come to pass with the spatstat2 package ? Is it available ?
Thank you for your help!
Keith Helfrich
Regarding point 1:
I'm no expert on this, but I think the package stpp on CRAN could be useful.
Regarding point 2:
spatstat2 is definitely not available yet, and realistically it will not come out this year (personal correspondence with the authors).
Related
I am looking for an R package which can run "Spatial Vector Autoregression".
tandfonline.com/doi/full/10.1080/17421770701346689
According to Chen and Conley (2001), this is a "vector autoregression (VAR) whose coefficient matrix and shock covariance matrix are functions of economic distances between agents. The impact of other agents’ variables on the conditional mean of a given agent’s variable is a function of their economic distances from this agent. Similarly, covariances of VAR shocks are functions of distances between agents in the previous period, a property we refer to as being isotropic."
(Chen, X & Conley, T.G. (2001) A new semiparametric spatial model for panel
time series, Journal of Econometrics, 105, 59–83)
Surprisingly, however, I could only see until "Spatial Autoregression" which is still not what I need for my purpose. May I get help finding the package for this please? Otherwise, may I know an official way to run this Spatial Vector Autoregression model using R programming?
I think I've found what you're looking for, devtools::install_github("James-Thorson/VAST"). VAST stands for "Vector-Autoregressive Spatio-Temporal." This package is a wrapper around a package that incorporates spatial modeling. Essentially it adds to it.
You can see coding examples here. If you want to look at help, use ?VAST::VAST and select one of the three hyperlinks at the bottom of the short description and details (make_settings, fit_model, and plot_results).
Please note:
When I installed this package to check out what it included, it came back with a conflict that the package TMB required an earlier version of the Matrix package. I had not had TMB installed before installing this package. I had no issues installing TMB independently (without a conflict with the version of the Matrix package). However when I called the library VAST it still gave me that error. When I called the library TMB, then the library VAST I didn't receive the warning and both libraries loaded.
hello am new to R programming in r studio . I will be analyzing the spectral data of raman spectrum in future.
which package will be useful to for the spectral data analysis.I would like to learn that package. I have attached the image how I want to analyze. Please give me suggestions, how to plot the graph as shown in the fig in r studio
thanks in advance
There is a free package called hyperSpec that was specifically designed to handle spectral data together with associated extra data (e.g. experimental parameters etc.). The package also provides interface for common operations, like baseline correction, selection of spectral ranges, normalization, PCA, etc. Moreover, there is a host of plotting functions.
You can install it from CRAN with install.packages("hyperSpec"), however, as of today the CRAN version is outdated. I would recommend you to fetch the recent build from gitHub and install it via Rstudio (look for packages->install->from package archive file).
hyperSpec comes with an extensive documentation and example datasets. To browse through tutorials, run
browseVignettes("hyperSpec")
Plotting is as easy as
plot(chondro) # left plot
qplotspc(chondro) + ggtitle("Example dataset") # right plot
To import your own data, look for functions inside of hyperSpec, whose name starts with read. Just start typing hyperSpec::read and a pop-up will appear. A lot of device-specific data formats are supported. See vignette("fileio") for details.
I'm currently working on a brief presentation for a graduate class in multivariate data analysis. It's on methods of displaying multivariate data (for human comprehension), and of the six methods we're supposed to present on, I've taken on radial visualization plots (specifically the type referred to as "RadViz") and survey plots (which are a variety of permutation matrix visualization, or so I've been led to understand from my research). While I have been able to find sufficient resources on the uses of these visualization methods, as well as their benefits/drawbacks, I'm coming up with problems finding code to implement them in R.
I have located two user-written functions that will do survey plots and radial visualization in R. These appear to part of the package "dprep", which has since been discontinued from CRAN--and try as I might, I cannot seem to get it to install as a package when I download the older version from the archive. Additionally, all of this code is now six years and several versions out of data, and I am hesitant to recommend it to classmates if it may become completely unusable at some point.
I suppose what I'm asking is if there is any easier or cleaner way--possibly as part of an existing package--to implement these visualizations in R, or if my only option is using the above (very old) code to do it. I'm aware of solutions in other programming languages (Python) as well as other pieces of software (Orange, VisuLab), but since the class is primarily based around using R, I'd like to be able to present in it if I can.
Sounds like we need to teach you to search. The google pathway is always available but for R functionality it sometimes is not sufficiently specific if the topic name is commonly used for other concepts. I often pair the search term with 'rproject'
https://www.google.com/search?q=radviz&ie=utf-8&oe=utf-8#q=radviz+rproject
Brings up:
http://www.cs.uml.edu/~phoffman/Radviz/readme.txt # R interface to C-implementation
... as well as many others but it would take some effort to sort through to find R-specific implementation.
I have many successes using the findFn-function in the sos package:
install.packages("sos")
library(sos)
Originally I thought this was just the ordinary radar chart but seems it might be something different.
> findFn("Radial Coordinate Visualization")
found 12 matches; retrieving 1 page
Downloaded 4 links in 3 packages.
The search on Radviz only brings up a single item, radviz2d, whose help page links to a surveyplot function in the same package 'dprep'. The term 'radial' alone brought up a large number, possibly unmanageable:
> findFn("radial plots")
found 456 matches; retrieving 20 pages, 400 matches.
2 3 4 5 6 7 8 9 10
11 12 13 14 15 16 17 18 19 20
Those terms deliver a somewhat more manageable number. Radar plots or spider plots are generally being used for discrete variables, but radial coordinate visualization appears to be a method of projecting multivariate associations on a two-dimensional domain. The 'circular' package also deals with display and statistics on continuous variables.
From the CRAN Archive I downloaded and unpackaed version 2.1 of radviz: dprep_2.1.tar.gz:
source('~/Downloads/dprep/R/radviz2d.R', chdir = TRUE)
mmnorm <-
function (data,minval=0,maxval=1)
{
d=dim(data)
c=class(data)
cnames=colnames(data)
classes=data[,d[2]]
data=data[,-d[2]]
minvect=apply(data,2,min)
maxvect=apply(data,2,max)
rangevect=maxvect-minvect
zdata=scale(data,center=minvect,scale=rangevect)
newminvect=rep(minval,d[2]-1)
newmaxvect=rep(maxval,d[2]-1)
newrangevect=newmaxvect-newminvect
zdata2=scale(zdata,center=FALSE,scale=(1/newrangevect))
zdata3=zdata2+newminvect
zdata3=cbind(zdata3,classes)
if (c=="data.frame") zdata3=as.data.frame(zdata3)
colnames(zdata3)=cnames
return(zdata3)
}
load("/Users/davidwinsemius/Downloads/dprep/data/my.iris.rda")
radviz2d(my.iris,"Iris")
The package also has several other functions including survey plot that are available in R, so they do not need to be compile. There is a compiled function in the package which I have not investigated.
I have released a new version of dprep. Edgar Acuna
I am analysing STATS19 road accident data, commendably made available to the public by the UK government. I would like to look at how clustered different types of accidents are. The "G function" (described here) can be used to measure the divergence of point patterns from cases of complete spatial randomness "CSR".
spatstat handles this kind of problem well, with the envelope function providing a visualisation for the extent to which the pattern diverges from the CSR for different distances.
As my colleague Dan Olner has pointed out, however, the results (shown below, showing great divergence from the CSR) do not necessarily show clustering - it could be simply that we are detecting the natural clustering of the road network, on which most road accidents occur. The plot below can be reproduced by cloning my GitHub repo and running the following (after running parts of WY.R):
r <- seq(0, sqrt(2)/6, by = 0.005)
acB1 <- elide(acB, scale = TRUE)
# acB1 <- acB1[1:50,] # for tiny subset
acB1 <- SpatialPoints(acB1)
# Calculate the G function for the points
envacB <- envelope(as(acB1, "ppp"), fun = Gest)
# Calculate the G function for the points
plot(envacB)
This issue is actually described by Adrian Baddeley (developer of spatstat) himself in the package's documentation:
points could be locations in one dimension (such as
road accidents recorded on a road network)
This is exactly the situation I am facing but I do not know how to modify the analysis presented above to constraint the CSR to (or better, near to - as not all accidents are precisely on the road - see below) the road network. (see data here).
One suggestion was to take random points from the road network and calculate the G function for this and compare it with my accident data, but that would not create a clear (statistically significant) bounding box. Any suggestions?
You are absolutely right that the perceived clustering could be due to the accidents occurring on the road network. This must be accounted for.
In spatstat the road network is represented by a "linnet" object, so you need to convert your road network to this format. I don't know the details of that, but I would guess you should look at the "shapefiles" vignette in spatstat (you might have to go through the line segment class "psp" to import things):
vignette("shapefiles", package="spatstat")
A point pattern on a linear network is of class "lpp", so this is the data format you need in the end. If you have managed to store your network as the linnet object "mynet" you should be able to do something like:
X <- as(acB1, "ppp")
X <- lpp(X, mynet)
This automatically projects your points onto the network. Now you can look at summary statistics on the network. I don't think the G function is implemented in this setup, but I know the K-function is (function "linearK"), so you could use that. The generic function envelope as you used in your code now calls envelope.lpp which makes sure that the CSR simulations also are generated on the network.
I hope some of this is useful albeit not very detailed. Have a look at the relevant help files in spatstat for more details:
help(lpp)
help(linnet)
help(linearK)
Do report back how you progress from here, then I (or more likely Adrian Baddeley) might be able to give you some more pointers.
I know that R is statistical pkg, but probably there is library to work with graphs and find shortest path btw 2 nodes.
PS actually, I've found igraph and e1071, which one is better?
Thank you
Sure, there's a Task View that gathers a fair number of the graph-related Packages. (The page linked to is a CRAN portal, which uses iframes, so i can't directly link to the Graph Task View. So from the page linked to here, click on Task Views near the top of the LHS column, then click on the Task View gR, near the bottom of the list.
Among the Packages there, igraph, for instance, has graph-theoretic functions such as you have mentioned in your Q.
igraph versus e1071--well, igraph is coded in C; it's very fast. I have not compared it with e1071 though.
What i do know is that these two packages differ a great deal in scope: e1071 is a collection of functions (at least originally) for a University course (i believe the unusual name 'e1071' refers to the course identifier), while. e1071 indeed contains a graph theoretic functions, but the majority of the Package's functions are directed to machine learning.
iGraph on the other hand is a dedicated graph theoretic Package. iGraph has many more dedicated functions, as well as constructors for a number of common graph types.