[R-sig-Geo] error in dudi.pca (adehabitat)

Mathieu Basille basille at biomserv.univ-lyon1.fr
Wed Apr 28 14:33:50 CEST 2010


Glad that it does work now.

But considering it is a marine species, I'm not sure what you want to do 
with data2enfa. This function returns 1) a data frame with the value for 
each pixel (that you can get directly with kasc2df) and 2) a vector of 
presence ($pr) which gives the number of localisations in each pixel of 
the map (i.e. not NA). For a perfect marine species, it should give you 
only 0s.

Now in your case, you get 99 localisations (on a total of 212) on the 
ground... Maybe that's a normal behaviour for this species, or maybe 
it's a problem of location error, but that's what made me think about 
what you exactly want to do.

Cheers,
Mathieu.


Consuelo Hermosilla a écrit :
> Hello Mathieu,
> 
> I cannot believe it!! I have tried adding the names, with less layers, 
> and it didn't work either, so I guessed that was not the problem. I 
> guess I have others problems too. But now it does work! I'm amazed. I'm 
> sorry you lost so much time. I deeply thank you.
> 
> Yes. the second and third columns were the coordinates, I apologize, I 
> thought I sent you a file with the coordinates only. And about falling 
> into the water, they must do that! it's a marine species.
> 
> Thank you very very much Mathieu,
> 
> Consuelo
> 
> -------------
> Consuelo Hermosilla
> PhD student
> Departamento de Ecología y Biología Animal
> Departamento de Bioquímica, Genética e Inmunología, Área de Genética
> Facultad de Ciencias del Mar
> Campus de As Lagoas-Marcosende
> Universidad de Vigo
> 36310 Vigo
> SPAIN
> Mobile: +34 692 633 298
> 
> oooO
> (     ) Oooo
>    (   (     )
>   _)    )  /
>         (_/
> 
> Stop Gaza Massacre
> 
> 
> On Wed, Apr 28, 2010 at 5:11 AM, Mathieu Basille 
> <basille at biomserv.univ-lyon1.fr <mailto:basille at biomserv.univ-lyon1.fr>> 
> wrote:
> 
>     Wow, this one gave me a real hard time, especially considering how
>     easy the solution was.
> 
>     In brief, you have to specify names in the list, in the as.kasc
>     function. Otherwise, none of the layers have actually names, which
>     induces a lot of problems afterwards.
> 
>     The fix is quite easy then. I took also some the liberty to clean
>     the code at different places:
> 
>     library(adehabitat)
> 
>     chl <- import.asc("chl-box_qt.asc")
>     sst <- import.asc("sst-box_QT.asc")
>     dep <- import.asc("dep-box_QT.asc")
>     euph <- import.asc("euph-box_QT.asc")
>     OX0 <- import.asc("OX0-box_QT.asc")
>     OX200 <- import.asc("OX200-box_QT.asc")
>     OX50 <- import.asc("OX50-box_QT.asc")
>     P0 <- import.asc("P0-box_QT.asc")
>     P100 <- import.asc("P100-box_QT.asc")
>     P125 <- import.asc("P125-box_QT.asc")
>     P150 <- import.asc("P150-box_QT.asc")
>     P200 <- import.asc("P200-box_QT.asc")
>     pre <- import.asc("pre-box_QT.asc")
> 
>     # The problem was here:
>     env_maps <- as.kasc(list(chl = chl, sst = sst, dep = dep, euph =
>     euph, OX0 = OX0, OX200 = OX200, OX50 = OX50, P0 = P0, P100 = P100,
>     P125 = P125, P150 = P150, P200 = P200, pre = pre))
> 
>     # You forgot to save the output of this, but in your case, that was not
>     # a problem
>     env_maps <- managNAkasc(env_maps)  # just to check
> 
>     presence <- read.csv("presence5.csv")
>     # I assumed that the second and third columns give X-Y coordinates. But
>     # it is somehow weird since many of them fall in the water -- assuming
>     # it's islands and water
>     octopus.hab <- data2enfa(env_maps, presence[, 2:3])
> 
> 
>     pca.octopus <- dudi.pca(octopus.hab$tab, scannf = FALSE)
> 
> 
>     Hope this helps,
> 
>     Cheers,
>     Mathieu.
> 
> 
>     Consuelo Hermosilla a écrit :
> 
>         Dear Mathieu,
> 
> 
>         Thanks for your quick reply!!! :)
> 
>         I thought that too, but then, why I'm able to plot the imported
>         map? It makes no sense, I wouldn't be able to plot it if there
>         was an error there, would I?
> 
>         This was my code:
> 
>         library(adehabitat)
> 
>         chl= import.asc("chl-box_qt.asc", type ="numeric")
>         sst = import.asc("sst-box_QT.asc", type ="numeric")
>         dep = import.asc("dep-box_QT.asc", type ="numeric")
>         euph = import.asc("euph-box_QT.asc", type ="numeric")
>         OX0 = import.asc("OX0-box_QT.asc", type ="numeric")
>         OX200 = import.asc("OX200-box_QT.asc", type ="numeric")
>         OX50 = import.asc("OX50-box_QT.asc", type ="numeric")
>         P0 = import.asc("P0-box_QT.asc", type ="numeric")
>         P100 = import.asc("P100-box_QT.asc", type ="numeric")
>         P125 = import.asc("P125-box_QT.asc", type ="numeric")
>         P150 = import.asc("P150-box_QT.asc", type ="numeric")
>         P200 = import.asc("P200-box_QT.asc", type ="numeric")
>         pre = import.asc("pre-box_QT.asc", type ="numeric")
> 
>         env_maps = as.kasc(list(chl, sst, dep, euph, OX0, OX200, OX50,
>         P0, P100, P125, P150, P200, pre))
> 
>         managNAkasc (env_maps)  # just to check
>         presence <- read.csv("presence.csv")
>         octopus.hab <- data2enfa(env_maps, presence)
>         pca.octopus <- dudi.pca(octopus.hab$tab, scannf=FALSE)
> 
>         Can I attach files? How do you want me to provide data?
> 
>         Consuelo
> 
>         -------------
>         Consuelo Hermosilla
>         PhD student
>         Departamento de Ecología y Biología Animal
>         Departamento de Bioquímica, Genética e Inmunología, Área de Genética
>         Facultad de Ciencias del Mar
>         Campus de As Lagoas-Marcosende
>         Universidad de Vigo
>         36310 Vigo
>         SPAIN
>         Mobile: +34 692 633 298
> 
>         oooO
>         (     ) Oooo
>           (   (     )
>          _)    )  /
>                (_/
> 
>         Stop Gaza Massacre
> 
> 
>         On Tue, Apr 27, 2010 at 11:31 PM, Mathieu Basille
>         <basille at biomserv.univ-lyon1.fr
>         <mailto:basille at biomserv.univ-lyon1.fr>
>         <mailto:basille at biomserv.univ-lyon1.fr
>         <mailto:basille at biomserv.univ-lyon1.fr>>> wrote:
> 
>            Dear Consuelo,
> 
>            I guess the error just propagates from the initial import,
>         and has
>            nothing to do with dudi.pca (which is by the way from the ade4
>            package -- not directly related to adehabitat).
> 
>            Your approach otherwise seems (quite) OK. Unfortunately, you
>         didn't
>            provide enough details to check. Could you provide the whole
>         code,
>            with possibly some data, so that we can reproduce the problem?
> 
>            Cheers,
>            Mathieu.
> 
> 
> 
>            Consuelo Hermosilla a écrit :
> 
>                Hi folks,
> 
>                I'm trying to implement an ecological niche factor
>         analysis with
>                octopus but
>                I have some problems. I think it is related to the fact I
>         have
>                No-data
>                values. Since it's a marine species, I have land areas
>         where I
>                have no-data
>                values. Can I have grids with no-data values?
> 
>                The thing is I'm able to import the ascii grid (using
>                import.asc) and I'm
>                even able to plot it (and see the image), so I guessed I
>         have no
>                problems
>                with the no-data values. If I checked the grid, I got this:
> 
>                str(chl)
>                 asc [1:1214, 1:761] NA NA NA NA NA NA NA NA NA NA ...
>                 - attr(*, "xll")= num -18.6
>                 - attr(*, "yll")= num 16.7
>                 - attr(*, "cellsize")= num 0.05
>                 - attr(*, "type")= chr "numeric"
> 
>                It looks wrong, but it's OK since my first values are
>         indeed NA.
>                In fact,
>                besides the fact I'm able to plot it, I can calculate
>         grid means
>                and other
>                stats, so I think the problem is not here. Then, when I
>         grouped
>                all the
>                grids (with the as.kasc function), I got this:
> 
>                str(env_maps)
>                Classes ?kasc? and 'data.frame':        923854 obs. of  13
>                variables:
>                 $ : num  NA NA NA NA NA NA NA NA NA NA ...
>                 $ : num  NA NA NA NA NA NA NA NA NA NA ...
>                 $ : num  NA NA NA NA NA NA NA NA NA NA ...
>                 $ : num  NA NA NA NA NA NA NA NA NA NA ...
>                 $ : num  NA NA NA NA NA NA NA NA NA NA ...
>                 $ : num  NA NA NA NA NA NA NA NA NA NA ...
>                 $ : num  NA NA NA NA NA NA NA NA NA NA ...
>                 $ : num  NA NA NA NA NA NA NA NA NA NA ...
>                 $ : num  NA NA NA NA NA NA NA NA NA NA ...
>                 $ : num  NA NA NA NA NA NA NA NA NA NA ...
>                 $ : num  NA NA NA NA NA NA NA NA NA NA ...
>                 $ : num  NA NA NA NA NA NA NA NA NA NA ...
>                 $ : num  NA NA NA NA NA NA NA NA NA NA ...
>                 - attr(*, "cellsize")= num 0.05
>                 - attr(*, "xll")= num -18.6
>                 - attr(*, "yll")= num 16.7
>                 - attr(*, "ncol")= int 1214
>                 - attr(*, "nrow")= int 761
>                 - attr(*, "type")= chr  "numeric" "numeric" "numeric"
>         "numeric" ...
> 
>                Still looks wrong, but it shouldn't be. Then, I proceed
>         with the
>                data2enfa
>                function, that seemed to work. But in the next step, when
>         I was
>                calculating
>                the dudi.pca, it failed, with this error:
> 
>                Error in `rownames<-`(`*tmp*`, value = c("1", "2", "3", "4",
>                "5", "6",  :
>                 attempt to set rownames on object with no dimensions
> 
>                I checked the data2enfa result and I got this:
> 
>                List of 4
>                 $ tab  :'data.frame':  923854 obs. of  0 variables
>                 $ pr   : int [1:923854] 0 0 0 0 0 0 0 0 0 0 ...
>                 $ index: int [1:923854] 1 2 3 4 5 6 7 8 9 10 ...
>                 $ attr :Class 'mapattr'  atomic [1:1] 0
>                 .. ..- attr(*, "xll")= num -18.6
>                 .. ..- attr(*, "yll")= num 16.7
>                 .. ..- attr(*, "cellsize")= num 0.05
>                 .. ..- attr(*, "nrow")= int 761
>                 .. ..- attr(*, "ncol")= int 1214
>                 - attr(*, "class")= chr "dataenfa"
> 
>                When I check the $tab, I got this:
> 
>                octopus.hab$tab
>                data frame with 0 columns and 923854 rows*
> 
>                *And I have no idea of what's wrong.... any ideas? do you
>                suggest anything?
>                Why do I have 0 columns and 923854 rows? Is that
>         possible? Can
>                the data2enfa
>                funcion deal with no-data values?
> 
>                I tried the magagNAkasc, but doesn't work...
> 
>                managNAkasc (env_maps)
>                Raster map of class "kasc":
>                Cell size:  0.05
>                Number of rows:  761
>                Number of columns:  1214
> 
>                Variables measured:
>                1. : numeric
>                Error in .subset2(x, i, exact = exact) :
>                 attempt to select less than one element
> 
>                I have tried in Windows Vista and Linux (both R 2.10.1 and
>                adehabitat v
>                1.83.
> 
>                I'd appreciate any help!!
> 
>                Thanks!!!
> 
>                Consuelo
> 
>                       [[alternative HTML version deleted]]
> 
>                _______________________________________________
>                R-sig-Geo mailing list
>                R-sig-Geo at stat.math.ethz.ch
>         <mailto:R-sig-Geo at stat.math.ethz.ch>
>         <mailto:R-sig-Geo at stat.math.ethz.ch
>         <mailto:R-sig-Geo at stat.math.ethz.ch>>
> 
>                https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> 
> 
>            --
>            ~$ whoami
>            Mathieu Basille, Post-Doc
> 
>            ~$ locate
>            Laboratoire d'Écologie Comportementale et de Conservation de
>         la Faune
>            + Centre d'Étude de la Forêt
>            Département de Biologie
>            Université Laval, Québec
> 
>            ~$ info
>            http://ase-research.org/basille
> 
>            ~$ fortune
>            ``If you can't win by reason, go for volume.''
>            Calvin, by Bill Watterson.
> 
> 
> 
>     -- 
> 
>     ~$ whoami
>     Mathieu Basille, Post-Doc
> 
>     ~$ locate
>     Laboratoire d'Écologie Comportementale et de Conservation de la Faune
>     + Centre d'Étude de la Forêt
>     Département de Biologie
>     Université Laval, Québec
> 
>     ~$ info
>     http://ase-research.org/basille
> 
>     ~$ fortune
>     ``If you can't win by reason, go for volume.''
>     Calvin, by Bill Watterson.
> 
> 

-- 

~$ whoami
Mathieu Basille, Post-Doc

~$ locate
Laboratoire d'Écologie Comportementale et de Conservation de la Faune
+ Centre d'Étude de la Forêt
Département de Biologie
Université Laval, Québec

~$ info
http://ase-research.org/basille

~$ fortune
``If you can't win by reason, go for volume.''
Calvin, by Bill Watterson.



More information about the R-sig-Geo mailing list