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]]
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).> 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.
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.