[R] problem with mahal function Package dismo

Jon Olav Skoien jon.skoien at jrc.ec.europa.eu
Wed Aug 7 15:07:54 CEST 2013


Hi Ernesto,

I think the issue is that the mahal function treats the arguments 
differently depending on the class.
If you pass the arguments x and p as raster and data.frame/matrix, it 
will use the values of x at the locations defined in p as training data.
If you pass a data.frame, it will assume that you have already extracted 
the training data, and produce a mean vector and covariance matrix 
directly from these. The function will not understand why you submit an 
additional data.frame with locations and give the error you got.
showMethods(mahal)
shows you the different possible combinations of arguments.
It was not clear from the post why you want to use a data.frame, so I 
cannot provide you with a solution to your problem. Maybe you could 
consider interpolating the variables to the locations in Cfin?

Best wishes,
Jon


On 06-Aug-13 12:50, Ernesto Villarino wrote:
> Hi all,
> I want to apply mahal function using data.frame instead of raster data
> but I am having problems (see error message below). I want to use
> data.frame since we have seasonal data (the species distribute
> differently as a function of months).
>
>> head (predictor)
>         OCPT     x1XM     z        Pc     pHxM      MLD
> 38 21.23519 36.24476 -3164  8.836913 8.082310 68.09159
> 39 21.13811 36.25013 -2487  8.451318 8.077561 57.78384
> 40 21.03920 36.25259 -2025  8.132195 8.073292 62.59614
> 41 20.94312 36.25257 -3409  7.851401 8.069450 55.83329
> 79 21.22135 36.10911   -40 18.707443 8.108031 42.55479
> 80 21.14884 36.13638 -2800 21.133693 8.063561 64.28003
>
>> head (Cfin)
>     Lat Long
> 38  35  -38
> 39  35  -37
> 40  35  -36
> 41  35  -35
> 79  36  -75
> 80  36  -74
>
>> mm<-mahal (predictor,Cfin)
> Error en (function (classes, fdef, mtable)  :
>    unable to find an inherited method for function 'mahal' for signature
> '"data.frame", "data.frame"'
>
> Can you help me ??
> Thanks,
> Regards,
> Ernesto
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.


-- 
Jon Olav Skøien
Joint Research Centre - European Commission
Institute for Environment and Sustainability (IES)
Land Resource Management Unit

Via Fermi 2749, TP 440,  I-21027 Ispra (VA), ITALY

jon.skoien at jrc.ec.europa.eu
Tel:  +39 0332 789206

Disclaimer: Views expressed in this email are those of the individual and do not necessarily represent official views of the European Commission.



More information about the R-help mailing list