Skip to content

problem with mahal function Package dismo

3 messages · Ernesto Villarino, David L Carlson, Jon Olav Skoien

#
It appears that you are trying to pass a data.frame to the function
and it is complaining. You didn't give us enough information to know
for sure (e.g. str(predictor) and str(Cfin)), but you could try

mm<-mahal (as.matrix(predictor), as.matrix(Cfin))

-------------------------------------
David L Carlson
Associate Professor of Anthropology
Texas A&M University
College Station, TX 77840-4352

-----Original Message-----
From: r-help-bounces at r-project.org
[mailto:r-help-bounces at r-project.org] On Behalf Of Ernesto Villarino
Sent: Tuesday, August 6, 2013 5:51 AM
To: r-help at r-project.org
Subject: Re: [R] problem with mahal function Package dismo

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).
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
Lat Long
38  35  -38
39  35  -37
40  35  -36
41  35  -35
79  36  -75
80  36  -74
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


______________________________________________
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.
#
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: