Converting spatialPointsDataFrame into ppp

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Converting spatialPointsDataFrame into ppp

Agustin Lobo-2
Hi!

Is it possible (and if yes, how) to convert from an spatialPointsDataFrame
to a ppp object (selecting the appropriate variable in the
dataframe) so that I can run Kest ?
I've tried with as.ppp with no success.

(I always have a bad time converting among the different spatial
objects in R, I promise contributing a flow chart soon, or is ti
included in the new book?).

Thanks!

Agus
--
Dr. Agustin Lobo
Institut de Ciencies de la Terra "Jaume Almera" (CSIC)
LLuis Sole Sabaris s/n
08028 Barcelona
Spain
Tel. 34 934095410
Fax. 34 934110012
email: Agustin.Lobo at ija.csic.es
http://www.ija.csic.es/gt/obster



Reply | Threaded
Open this post in threaded view
|

Converting spatialPointsDataFrame into ppp

Marcelino de la Cruz
 From the help of as.ppp {maptools}


data(meuse)

 > class(meuse)
[1] "SpatialPointsDataFrame"
attr(,"package")
[1] "sp"


coordinates(meuse) = ~x+y
zn1 <- as(meuse["zinc"], "ppp")
zn1

And then try this:

Kest(zn1)


Regards,

Marcelino


At 10:44 08/05/2008, Agustin Lobo wrote:

>Hi!
>
>Is it possible (and if yes, how) to convert from an spatialPointsDataFrame
>to a ppp object (selecting the appropriate variable in the
>dataframe) so that I can run Kest ?
>I've tried with as.ppp with no success.
>
>(I always have a bad time converting among the different spatial
>objects in R, I promise contributing a flow chart soon, or is ti
>included in the new book?).
>
>Thanks!
>
>Agus
>--
>Dr. Agustin Lobo
>Institut de Ciencies de la Terra "Jaume Almera" (CSIC)
>LLuis Sole Sabaris s/n
>08028 Barcelona
>Spain
>Tel. 34 934095410
>Fax. 34 934110012
>email: Agustin.Lobo at ija.csic.es
>http://www.ija.csic.es/gt/obster
>
>_______________________________________________
>R-sig-Geo mailing list
>R-sig-Geo at stat.math.ethz.ch
>https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

________________________________

Marcelino de la Cruz Rot

Departamento de  Biolog?a Vegetal
E.U.T.I. Agr?cola
Universidad Polit?cnica de Madrid
28040-Madrid
Tel.: 91 336 54 35
Fax: 91 336 56 56
marcelino.delacruz at upm.es



Reply | Threaded
Open this post in threaded view
|

Re: Converting spatialPointsDataFrame into ppp

Aurelie C.Godin
Dear all,

I am new to spatial and point process analysis (as well as R), however most of my Ph.D. will rely heavily on these tools *sighs :) I am starting a new chapter where I intend to model elasmobranch i.e., shark and skate catch in the Northwest Atlantic Canadian waters using point process modeling. I am interested in investigating the spatial, temporal, and space–time clustering of catch events conditioned upon the distribution of fishing locations.

I have been following the R-sig-geo mails and found many great reading suggestions, which were very helpful! Thank you. I would like to do some exploratory data analysis on a small subset of my database i.e., solely shark catch for the year 2009 (546 observations), but I am running (not surprisingly) into errors and warnings!

Would be grateful to anyone's help!
I am trying to convert my SpatialPointsDataFrame into a ppp. Right now, I would just like to make a ppp with "catch" as a mark (this is the catch size in kg).

> class(SHK09)
[1] "SpatialPointsDataFrame"
attr(,"package")
[1] "sp"

#SHK09 looks as follow
> head(as.data.frame(SHK09))
  year month day tripID setID gear NAFO     x      y kept discard fmonth fgear
1 2009     8  17    345    16    5   22 55.41 -58.46    0     227    Aug    GN
2 2009     2   1      3     2    1   23 52.36 -51.24    0     450    Feb    OT
3 2009     7  28    296     4    5    9 68.37 -59.34    0     250    Jul    GN
4 2009     9   5    339    29    5    9 68.27 -59.53    0      10    Sep    GN
5 2009     8  28    316    44    5    9 68.38 -64.36    0    1400    Aug    GN
6 2009     9   1    316    49    5    9 69.26 -64.50    0     200    Sep    GN
      fNAFO        t.spp.name t.spp.category         elasmo.name elasmo.category
1        2H GREENLAND HALIBUT              0 SHARKS,DOGFISH (NS)               1
2        2J GREENLAND HALIBUT              0     SHARK,GREENLAND               1
3 BaffinIsd GREENLAND HALIBUT              0     SHARK,GREENLAND               1
4 BaffinIsd GREENLAND HALIBUT              0     SHARK,GREENLAND               1
5 BaffinIsd GREENLAND HALIBUT              0     SHARK,GREENLAND               1
6 BaffinIsd GREENLAND HALIBUT              0     SHARK,GREENLAND               1
  catch logcatch
1   227 5.429346
2   450 6.111467
3   250 5.525453
4    10 2.397895
5  1400 7.244942
6   200 5.303305

#I tried to do the following as suggested by prior email, however, I get this following error message
>coordinates(SHK09) = ~x+y
Error in `coordinates<-`(`*tmp*`, value = ~x + y) :
  setting coordinates cannot be done on Spatial objects, where they have already been set

#so decided to proceed as follow
>catch <- as(SHK09["catch"], "ppp")
Error in as(SHK09["catch"], "ppp") :
  no method or default for coercing "SpatialPointsDataFrame" to "ppp"

Ideas?
Thank you very much in advance!

~~Aurelie

Aurelie Cosandey-Godin
Ph.D. Candidate, Department of Biology, Dalhousie University
Industrial Graduate Fellow, WWF-Canada
Email: godina@dal.ca | Web: wormlab.biology.dal.ca
-----------------------------------------------------------------------------------------------------
Want to learn more about sharks in Atlantic Canada? Visit ShARCC! www.atlanticsharks.org



Aurelie Cosandey-Godin, Ph.D.
Postdoctoral Research Fellow, Department of Biology, Dalhousie University
godina@dal.ca | wormlab.biology.dal.ca
Reply | Threaded
Open this post in threaded view
|

Re: Converting spatialPointsDataFrame into ppp

Roger Bivand
Administrator
On Fri, 16 Sep 2011, GodinA wrote:

> Dear all,
>
> I am new to spatial and point process analysis (as well as R), however most
> of my Ph.D. will rely heavily on these tools *sighs :) I am starting a new
> chapter where I intend to model elasmobranch i.e., shark and skate catch in
> the Northwest Atlantic Canadian waters using point process modeling. I am
> interested in investigating the spatial, temporal, and space–time clustering
> of catch events conditioned upon the distribution of fishing locations.
>
> I have been following the R-sig-geo mails and found many great reading
> suggestions, which were very helpful! Thank you. I would like to do some
> exploratory data analysis on a small subset of my database i.e., solely
> shark catch for the year 2009 (546 observations), but I am running (not
> surprisingly) into errors and warnings!
>
> Would be grateful to anyone's help!
> I am trying to convert my SpatialPointsDataFrame into a ppp. Right now, I
> would just like to make a ppp with "catch" as a mark (this is the catch size
> in kg).
>
>> class(SHK09)
> [1] "SpatialPointsDataFrame"
> attr(,"package")
> [1] "sp"
>
> #SHK09 looks as follow
>> head(as.data.frame(SHK09))
>  year month day tripID setID gear NAFO     x      y kept discard fmonth
> fgear
> 1 2009     8  17    345    16    5   22 55.41 -58.46    0     227    Aug
> GN
> 2 2009     2   1      3     2    1   23 52.36 -51.24    0     450    Feb
> OT
> 3 2009     7  28    296     4    5    9 68.37 -59.34    0     250    Jul
> GN
> 4 2009     9   5    339    29    5    9 68.27 -59.53    0      10    Sep
> GN
> 5 2009     8  28    316    44    5    9 68.38 -64.36    0    1400    Aug
> GN
> 6 2009     9   1    316    49    5    9 69.26 -64.50    0     200    Sep
> GN
>      fNAFO        t.spp.name t.spp.category         elasmo.name
> elasmo.category
> 1        2H GREENLAND HALIBUT              0 SHARKS,DOGFISH (NS)
> 1
> 2        2J GREENLAND HALIBUT              0     SHARK,GREENLAND
> 1
> 3 BaffinIsd GREENLAND HALIBUT              0     SHARK,GREENLAND
> 1
> 4 BaffinIsd GREENLAND HALIBUT              0     SHARK,GREENLAND
> 1
> 5 BaffinIsd GREENLAND HALIBUT              0     SHARK,GREENLAND
> 1
> 6 BaffinIsd GREENLAND HALIBUT              0     SHARK,GREENLAND
> 1
>  catch logcatch
> 1   227 5.429346
> 2   450 6.111467
> 3   250 5.525453
> 4    10 2.397895
> 5  1400 7.244942
> 6   200 5.303305
>
> #I tried to do the following as suggested by prior email, however, I get
> this following error message
>> coordinates(SHK09) = ~x+y
> Error in `coordinates<-`(`*tmp*`, value = ~x + y) :
>  setting coordinates cannot be done on Spatial objects, where they have
> already been set
Well, that is what you would expect.

>
> #so decided to proceed as follow
>> catch <- as(SHK09["catch"], "ppp")
> Error in as(SHK09["catch"], "ppp") :
>  no method or default for coercing "SpatialPointsDataFrame" to "ppp"
>

Did you look at the vignette for the spatstat package about handling
shapefiles? You would note that you need the maptools package, which also
contains the as() coercion functions. They are there, rather than in sp or
spatstat, to try to avoid unwanted dependencies between packages.

However, I doubt whether your data are a marked point process - the catch
positions were decided by someone, not, say, the fish? Have you thought of
trying the bubble() function in sp?

Roger

> Ideas?
> Thank you very much in advance!
>
> ~~Aurelie
>
> Aurelie Cosandey-Godin
> Ph.D. Candidate, Department of Biology, Dalhousie University
> Industrial Graduate Fellow, WWF-Canada
> Email: [hidden email] | Web: wormlab.biology.dal.ca
> -----------------------------------------------------------------------------------------------------
> Want to learn more about sharks in Atlantic Canada? Visit ShARCC!
> www.atlanticsharks.org
>
>
>
>
>
> --
> View this message in context: http://r-sig-geo.2731867.n2.nabble.com/Converting-spatialPointsDataFrame-into-ppp-tp2764866p6801137.html
> Sent from the R-sig-geo mailing list archive at Nabble.com.
>
> _______________________________________________
> R-sig-Geo mailing list
> [hidden email]
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
--
Roger Bivand
Department of Economics, NHH Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: [hidden email]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Roger Bivand
Department of Economics
Norwegian School of Economics
Helleveien 30
N-5045 Bergen, Norway
Reply | Threaded
Open this post in threaded view
|

Re: Converting spatialPointsDataFrame into ppp

Aurelie C.Godin
Thank you very much for this quick reply Dr. Bivand.
I am taking good notes of your suggestions.

I'm a little concern about your comments that my data are not a marked point process and would like to verify with you a few points. You are correct that my points - the catch positions are essentially fishermen decisions. However, I am using at-sea observer data, which are (technically) random sampling of a subset of all fishing effort (usually between 5-15 percent/year, although it varies between years, fisheries, and regions). As a starting point, I would like to reproduce what Gardner et al. (2008) have done. [Gardner B, Sullivan PJ, Morreale SJ, Epperly SP. Spatial and temporal statistical analysis of bycatch data: patterns of sea turtle bycatch in the North Atlantic. Canadian Journal of Fisheries and Aquatic Sciences. 2008;65(11):2461-2470. Available from: http://www.nrcresearchpress.com/doi/abs/10.1139/F08-152].
However, my data are somewhat more complex since I am dealing with different fishing gears (over 15 types) over the spend of 15 years (1995-2010). I would like to go beyond describing the space-time clustering of catch events and try to model these events to oceanographical variables, such as temperature and ocean-color derived chlorophyll concentration.

I would be grateful for any of your thoughts, comments, and/or suggestions.
Thank you very much for your time,

Best,
~~Aurelie


Aurelie Cosandey-Godin, Ph.D.
Postdoctoral Research Fellow, Department of Biology, Dalhousie University
godina@dal.ca | wormlab.biology.dal.ca
Reply | Threaded
Open this post in threaded view
|

Re: Converting spatialPointsDataFrame into ppp

Roger Bivand
Administrator
On Sat, 17 Sep 2011, GodinA wrote:

> Thank you very much for this quick reply Dr. Bivand.
> I am taking good notes of your suggestions.
>
> I'm a little concern about your comments that my data are not a marked point
> process and would like to verify with you a few points. You are correct that
> my points - the catch positions are essentially fishermen decisions.

Are you studying the spatial decisions of the fishermen, that is, is it
the clustering of catch data in space that is your main concern? You say
that you have a sample - in general point patterns should be complete, not
samples, because the sampling process could obscure the underlying spatial
process.

> However, I am using at-sea observer data, which are (technically) random
> sampling of a subset of all fishing effort (usually between 5-15
> percent/year, although it varies between years, fisheries, and regions). As
> a starting point, I would like to reproduce what Gardner et al. (2008) have
> done. [Gardner B, Sullivan PJ, Morreale SJ, Epperly SP. Spatial and temporal
> statistical analysis of bycatch data: patterns of sea turtle bycatch in the
> North Atlantic. Canadian Journal of Fisheries and Aquatic Sciences.
> 2008;65(11):2461-2470. Available from:
> http://www.nrcresearchpress.com/doi/abs/10.1139/F08-152].

Only for subscribing institutions, I think. The fact that something has
been published doesn't necessarily make it sensible (I don't have access
to this case, speaking generally; from the abstract they seem to be
looking at bycatch spatial patterns using point pattern analysis, the
abstract doesn't say if they had access to all bycatch data).

> However, my data are somewhat more complex since I am dealing with different
> fishing gears (over 15 types) over the spend of 15 years (1995-2010). I
> would like to go beyond describing the space-time clustering of catch events
> and try to model these events to oceanographical variables, such as
> temperature and ocean-color derived chlorophyll concentration.

This implies inhomogeneity in the spatial process induced by the
space-time-varying covariates, so is rather ambitious in a point process
setting. It feels much more like a GLMM or GAMM, not least because the
paper you cite deals with bycatch (so clustering is arguably not caused by
the decisions of the fishermen), and you are dealing with catch, which is
caused by the decisions, and you only have a sample.

I'm not a fisheries person, it just struck me that it didn't seem obvious
that a marked point process was a helpful representation of your problem.
I'm sure others on this list have comments and ideas.

Hope this helps,

Roger

>
> I would be grateful for any of your thoughts, comments, and/or suggestions.
> Thank you very much for your time,
>
> Best,
> ~~Aurelie
>
>
>
>
> -----
> Aurelie Cosandey-Godin
> Ph.D. Candidate, Department of Biology
> Industrial Graduate Fellow, WWF-Canada
>
> Dalhousie University | Biology Dept. |Halifax, NS, Canada
> Email: [hidden email] | Web: wormlab.biology.dal.ca
> --------------------------------------------------------------------------
> Want to learn more about sharks in Atlantic Canada? Visit ShARCC! www.atlanticsharks.org
> --
> View this message in context: http://r-sig-geo.2731867.n2.nabble.com/Converting-spatialPointsDataFrame-into-ppp-tp2764866p6804881.html
> Sent from the R-sig-geo mailing list archive at Nabble.com.
>
> _______________________________________________
> R-sig-Geo mailing list
> [hidden email]
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

--
Roger Bivand
Department of Economics, NHH Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: [hidden email]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Roger Bivand
Department of Economics
Norwegian School of Economics
Helleveien 30
N-5045 Bergen, Norway