Help with ENFA in R

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

Help with ENFA in R

JonathanAronson
Hello there
I am really hoping someone out there can help me. I have read the various forums but havent found information that can help me.
I am running an ENFA in R for 12 species using 15 environmental variables. Below is my code and some questions:


library(ade4)
library(adehabitat)
test<- read.csv("Species_Localities/R.blasii.csv", header=T)
var1<- import.asc("Data/bio_01.asc")
var2<- import.asc("Data/bio_12.asc")
var3<- import.asc("Data/Aridity.asc")
var4<- import.asc("Data/altitude.asc")
var5<- import.asc("Data/unpalatable.asc")
var6<- import.asc("Data/thicket.asc")
var7<- import.asc("Data/succulent.asc")
var8<- import.asc("Data/shrubland.asc")
var9<- import.asc("Data/rainforest.asc")
var10<- import.asc("Data/mosaic.asc")
var11<- import.asc("Data/mopane.asc")
var12<- import.asc("Data/misavanna.asc")
var13<- import.asc("Data/hydro.asc")
var14<- import.asc("Data/fynbos.asc")
var15<- import.asc("Data/desert.asc")
map<- as.kasc(list(bio_01 = var1, bio_12 = var2, Aridity = var3, altitude = var4, unpalatable = var5, thicket = var6, succulent = var7, shrubland = var8, rainforest = var9, mosaic = var10, mopane = var11, misavanna = var12, hydro = var13, fynbos = var14, desert = var15))
enfatest<- data2enfa(map, test)
pc <- dudi.pca(enfatest$tab, scannf = FALSE, nf = 1)
enfatest1 <- enfa(pc, enfatest$pr, scannf = FALSE)
renfa <- randtest(enfatest1, nrepet=999)
list(enfatest1$m)
list(enfatest1$s)
list(enfatest1$co)
hist(enfatest1)
hist(enfatest1, scores = FALSE, type = "l")
image(enfatest1)
list(renfa$expvar)
list(renfa$pvalue)
list(renfa$obs)
scatter(enfatest1)
niche.test(map, test, nrep = 999, o.include = TRUE)

list(enfatest1$m) has given me the global marginality for each species and those are:

Species            Marginality
R.a                  4.8
R.b                 12.47
R.ca                 19.27
R.cl                 15.16
R.da                 12.36
R.de                 15.31
R.e                 12.19
R.f                  6.07
R.h                  9.65
R.l                  9.14
R.si                 13.7
R.sw                 13.11

I do not know how to get the global tolerance scores. Can you please help me with that?

I also do not know what the randomisation test for ENFA does. Could you please explain that?

I am unsure about what list(renfa$expvar), list(renfa$pvalue), list(renfa$obs) are telling me. I get a p-value of 0.001.

I have tried to test the significance of my results using a Monte Carlo test but i get this error when I run the code:

Error in niche.test(map, test, nrepet = 999, o.include = TRUE) :
  should be an object of class SpatialPixelsDataFrame


Please can someone provide some assistance because I have been stuck with this for months.
Thank you in advance
Jonathan
Reply | Threaded
Open this post in threaded view
|

Re: Help with ENFA in R

Mathieu Basille-2
Dear Jonathan,

Here are a few comments:

1) I strongly suggest that you update to 'adehabitatHS', which has
superseded the good-old 'adehabitat'. See [1]. It will solve your error
with 'niche.test'.

2) For the tolerance, 'niche.test' will give you both the marginality and
the tolerance.

3) For the randomization test of the ENFA, please have a look at
?randtest.enfa, and at ?randtest for more details about the object returned.

4) You don't need to call 'list(...)' to get the values. For example,
'enfatest1$m' would give you the answer.

5) I would also advise you to check this reference [2] about comparison
between species niche. The function 'niche' in ade4 is probably what you're
looking for...

Hope this helps,
Mathieu.


[1] http://cran.r-project.org/web/packages/adehabitatHS/index.html

[2] Doledec, S.; Chessel, D. & Gimaret Carpentier, C. (2000) Niche
separation in community analysis: A new method. Ecology, 81: 2914-2927 doi
10.1890/0012-9658(2000)081[2914:NSICAA]2.0.CO;2


Le 04/09/2013 08:49 AM, JonathanAronson a écrit :

> Hello there
> I am really hoping someone out there can help me. I have read the various
> forums but havent found information that can help me.
> I am running an ENFA in R for 12 species using 15 environmental variables.
> Below is my code and some questions:
>
>
> library(ade4)
> library(adehabitat)
> test<- read.csv("Species_Localities/R.blasii.csv", header=T)
> var1<- import.asc("Data/bio_01.asc")
> var2<- import.asc("Data/bio_12.asc")
> var3<- import.asc("Data/Aridity.asc")
> var4<- import.asc("Data/altitude.asc")
> var5<- import.asc("Data/unpalatable.asc")
> var6<- import.asc("Data/thicket.asc")
> var7<- import.asc("Data/succulent.asc")
> var8<- import.asc("Data/shrubland.asc")
> var9<- import.asc("Data/rainforest.asc")
> var10<- import.asc("Data/mosaic.asc")
> var11<- import.asc("Data/mopane.asc")
> var12<- import.asc("Data/misavanna.asc")
> var13<- import.asc("Data/hydro.asc")
> var14<- import.asc("Data/fynbos.asc")
> var15<- import.asc("Data/desert.asc")
> map<- as.kasc(list(bio_01 = var1, bio_12 = var2, Aridity = var3, altitude =
> var4, unpalatable = var5, thicket = var6, succulent = var7, shrubland =
> var8, rainforest = var9, mosaic = var10, mopane = var11, misavanna = var12,
> hydro = var13, fynbos = var14, desert = var15))
> enfatest<- data2enfa(map, test)
> pc <- dudi.pca(enfatest$tab, scannf = FALSE, nf = 1)
> enfatest1 <- enfa(pc, enfatest$pr, scannf = FALSE)
> renfa <- randtest(enfatest1, nrepet=999)
> list(enfatest1$m)
> list(enfatest1$s)
> list(enfatest1$co)
> hist(enfatest1)
> hist(enfatest1, scores = FALSE, type = "l")
> image(enfatest1)
> list(renfa$expvar)
> list(renfa$pvalue)
> list(renfa$obs)
> scatter(enfatest1)
> niche.test(map, test, nrep = 999, o.include = TRUE)
>
> list(enfatest1$m) has given me the global marginality for each species and
> those are:
>
> Species            Marginality
> R.a                  4.8
> R.b                 12.47
> R.ca                 19.27
> R.cl                 15.16
> R.da                 12.36
> R.de                 15.31
> R.e                 12.19
> R.f                  6.07
> R.h                  9.65
> R.l                  9.14
> R.si                 13.7
> R.sw                 13.11
>
> I do not know how to get the global tolerance scores. Can you please help me
> with that?
>
> I also do not know what the randomisation test for ENFA does. Could you
> please explain that?
>
> I am unsure about what list(renfa$expvar), list(renfa$pvalue),
> list(renfa$obs) are telling me. I get a p-value of 0.001.
>
> I have tried to test the significance of my results using a Monte Carlo test
> but i get this error when I run the code:
>
> Error in niche.test(map, test, nrepet = 999, o.include = TRUE) :
>    should be an object of class SpatialPixelsDataFrame
>
>
> Please can someone provide some assistance because I have been stuck with
> this for months.
> Thank you in advance
> Jonathan
>
>
>
> --
> View this message in context: http://r-sig-geo.2731867.n2.nabble.com/Help-with-ENFA-in-R-tp7583243.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
>

--

~$ whoami
Mathieu Basille, PhD

~$ locate --details
University of Florida \\
Fort Lauderdale Research and Education Center
(+1) 954-577-6314
http://ase-research.org/basille

~$ fortune
« Le tout est de tout dire, et je manque de mots
Et je manque de temps, et je manque d'audace. »
  -- Paul Éluard

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: Help with ENFA in R

JonathanAronson
Hi Mathieu

Thank you so much for your quick response. I really appreciate the effort and thank you for your answers.

I am now using the AdehabitatHS package but still have some questions.

1) I am not sure what (renfa$expvar), (renfa$pvalue) and (renfa$obs) are actually telling me in the output. I have copied the output below:

(renfa$expvar)
    Std.Obs Expectation    Variance
  45.557688    7.316997   11.538948
> (renfa$pvalue)
[1] 0.001
> (renfa$obs)
[1] 162.072

2) because i am using AdehabitatHS do I not need the following line of code anymore:

map<- as.kasc(list(bio_01 = var1, bio_12 = var2, Aridity = var3, altitude = var4, unpalatable = var5, thicket = var6, succulent = var7, shrubland = var8, rainforest = var9, mosaic = var10, mopane = var11, misavanna = var12, hydro = var13, fynbos = var14, desert = var15))
enfatest<- data2enfa(map, test)

3) I also got two error messages:

> image(enfatest1)
Error in image.default(enfatest1) : 'z' must be a matrix

> niche.test(map, test, nrepet = 999, o.include = FALSE)
Warning messages:
1: In hist.default(x, plot = FALSE, br = xbr, freq = FALSE) :
  argument ‘freq’ is not made use of
2: In hist.default(y, plot = FALSE, br = ybr, freq = FALSE) :
  argument ‘freq’ is not made use of

Mathieu, could you please provide some assistance with these questions?
Thank you
Jonathan
Reply | Threaded
Open this post in threaded view
|

Re: Help with ENFA in R

Mathieu Basille-2
Le 04/09/2013 03:51 PM, JonathanAronson a écrit :

> Hi Mathieu
>
> Thank you so much for your quick response. I really appreciate the effort
> and thank you for your answers.
>
> I am now using the AdehabitatHS package but still have some questions.
>
> 1) I am not sure what (renfa$expvar), (renfa$pvalue) and (renfa$obs) are
> actually telling me in the output. I have copied the output below:
>
> (renfa$expvar)
>      Std.Obs Expectation    Variance
>    45.557688    7.316997   11.538948

$expvar gives you the expected value from the simulated set
('Expectation'), i.e. the mean of the simulated values, together with its
variance. 'Std.Obs' tells you how much the observed value differs from the
distribution: it is basically the ratio of the difference between the
observed and the mean of simulated values, over the standard deviation of
the simulated values. You expect a difference equal to the SD, i.e. a ratio
'Std.Obs' of 1.

>> (renfa$pvalue)
> [1] 0.001

This is the p-value of the test. See ?randtest for the details of the
computation.

>> (renfa$obs)
> [1] 162.072

This is the observed value (here the first specialization eigenvalue).

The best way to summarize the results is to simply print the object, by a
direct call to 'renfa' in your case. Then, use 'plot(renfa)' for a very
neat graphical display of the test.


> 2) because i am using AdehabitatHS do I not need the following line of code
> anymore:
>
> map<- as.kasc(list(bio_01 = var1, bio_12 = var2, Aridity = var3, altitude =
> var4, unpalatable = var5, thicket = var6, succulent = var7, shrubland =
> var8, rainforest = var9, mosaic = var10, mopane = var11, misavanna = var12,
> hydro = var13, fynbos = var14, desert = var15))
> enfatest<- data2enfa(map, test)

No you don't. adehabitatHS uses 'sp' classes. Please have a look at the
vignette of both packages for more details:

vignette("intro_sp")
vignette("adehabitatHS")


> 3) I also got two error messages:
>
>> image(enfatest1)
> Error in image.default(enfatest1) : 'z' must be a matrix

This is quite normal... Assuming 'enfatest1' is the result of the ENFA,
there's no image function for such object... Check the section on the ENFA
in the above cited vignette.

>> niche.test(map, test, nrepet = 999, o.include = FALSE)
> Warning messages:
> 1: In hist.default(x, plot = FALSE, br = xbr, freq = FALSE) :
>    argument ‘freq’ is not made use of
> 2: In hist.default(y, plot = FALSE, br = ybr, freq = FALSE) :
>    argument ‘freq’ is not made use of

Not sure here, but I bet that the problem comes also from the class of
'map' and/or 'test'. Check the vignette and the example of the function.

Mathieu.


> Mathieu, could you please provide some assistance with these questions?
> Thank you
> Jonathan
>
>
>
>
> --
> View this message in context: http://r-sig-geo.2731867.n2.nabble.com/Help-with-ENFA-in-R-tp7583243p7583258.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
>

--

~$ whoami
Mathieu Basille, PhD

~$ locate --details
University of Florida \\
Fort Lauderdale Research and Education Center
(+1) 954-577-6314
http://ase-research.org/basille

~$ fortune
« Le tout est de tout dire, et je manque de mots
Et je manque de temps, et je manque d'audace. »
  -- Paul Éluard

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: Help with ENFA in R

JonathanAronson
Hi Mathieu

Thank you again. You are really helping  me. Please forgive some of my questions because I am very knew to R and I have to teach this to myself.

AdehabitatHS is using a different method to read the raster files. So when I input this code: var1<- import.asc("Data/bio_01.asc") I get the following error - Error: could not find function "import.asc". This makes sense to me because sp classes are used. I have read both the vignettes and used the example code for the lynx data but I am still struggling to interpret what the vignettes are saying and to use my own data. The code map <- lynxjura$map seems to contain all the environmental data. I am not sure how to use the sp package to get my 15 environmental variables into a similar dataframe. The same goes for my csv files - do I still need to use read.csv or should I rather use something like $locs.

Thank you again
Jonathan


Reply | Threaded
Open this post in threaded view
|

Re: Help with ENFA in R

Clement Calenge
Dear Jonathan,

To import the maps, have a look at the function readAsciiGrid from the
package maptools.
To import the points, read.csv or read.table (use your prefered way to
import data in R).
Con
HTH,

Clément Calenge.

On 04/10/2013 09:59 AM, JonathanAronson wrote:

> Hi Mathieu
>
> Thank you again. You are really helping  me. Please forgive some of my
> questions because I am very knew to R and I have to teach this to myself.
>
> AdehabitatHS is using a different method to read the raster files. So when I
> input this code: var1<- import.asc("Data/bio_01.asc") I get the following
> error - Error: could not find function "import.asc". This makes sense to me
> because sp classes are used. I have read both the vignettes and used the
> example code for the lynx data but I am still struggling to interpret what
> the vignettes are saying and to use my own data. The code map <-
> lynxjura$map seems to contain all the environmental data. I am not sure how
> to use the sp package to get my 15 environmental variables into a similar
> dataframe. The same goes for my csv files - do I still need to use read.csv
> or should I rather use something like $locs.
>
> Thank you again
> Jonathan
>
>
>
>
>
>
> --
> View this message in context: http://r-sig-geo.2731867.n2.nabble.com/Help-with-ENFA-in-R-tp7583243p7583264.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
>


--
Clément CALENGE
Cellule d'appui à l'analyse de données
Direction des Etudes et de la Recherche
Office national de la chasse et de la faune sauvage
Saint Benoist - 78610 Auffargis
tel. (33) 01.30.46.54.14

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: Help with ENFA in R

JonathanAronson
Hi Clement

Thank you very much for your input. I have read the maptools information and seen the examples for readAsciiGrid. I would like to create a SpatailPixelDataFrame which contains the raster maps of 15 environmental variables. Therefore, similar to the lynxjura$map SpatailPixelDataFramewhich contains 4 environmental variables. How did you create the lynxjura$map data frame - can you please show me step by step? You suggested using the readAsciiGrid function to import my maps. Is this how I can create the SpatailPixelDataFrame with the 15 variables I need? I do not understand the example code to do this (I am new to R):

x <- readAsciiGrid(system.file("grids/test.ag", package="maptools")[1])
summary(x)
image(x)
xp <- as(x, "SpatialPixelsDataFrame")
abline(h=332000, lwd=3)
xpS <- xp[coordinates(xp)[,2] < 332000,]
summary(xpS)
xS <- as(xpS, "SpatialGridDataFrame")
summary(xS)
tmpfl <- paste(tempdir(), "testS.ag", sep="/")
writeAsciiGrid(xS, tmpfl)
axS <- readAsciiGrid(tmpfl)
opar <- par(mfrow=c(1,2))
image(xS, main="before export")
image(axS, main="after import")
par(opar)
unlink(tmpfl)

Thanks in advance
Jonathan
Reply | Threaded
Open this post in threaded view
|

Re: Help with ENFA in R

JonathanAronson
perhaps I can clarify my question a lit bit further:

With the adehabitat package I used the function as.kasc to create a single data frame with my 15 variables as Ive shown below:

map<- as.kasc(list(bio_01 = var1, bio_12 = var2, Aridity = var3, altitude = var4, unpalatable = var5, thicket = var6, succulent = var7, shrubland = var8, rainforest = var9, mosaic = var10, mopane = var11, misavanna = var12, hydro = var13, fynbos = var14, desert = var15))

However, in the adehabitatHS, what is the equivalent function to use to create the data frame which is equivalent to the lynxjura$map spatial pixel data frame? There is no as.kasc function. I have used the readAsciiGrid function in Maptools but I can only do that individually for each variable. How then can I combine these into a single data frame? I have thought of using the stack() function in the raster package.

I am really stuck here
Thanks to anyone who can help
Jonathan
Reply | Threaded
Open this post in threaded view
|

Re: Help with ENFA in R

Mathieu Basille-2
Jonathan,

Again, this is no more an adehabitat question: the whole idea of the new
series of packages (including adehabitatHS) is to rely on spatial R classes
that are available with sp. All adehabitat functions to handle maps (such
as as.kasc) have thus been removed.

This said, this should help:

library(maptools)
x <- readAsciiGrid(system.file("grids/test.ag", package="maptools")[1])
class(x@data)
head(na.omit(x@data))
x@data <- cbind(x@data, x@data * 2)
head(na.omit(x@data))

As you can see, the data attributes are stored in a data frame. One
possibility for you is then to import all your variables using
readAsciiGrid, and then cbind all @data into one (assuming all your rasters
have the same resolution and extent). There might be other solutions as well...

Lastly, read.csv is fine to import the point data. You'll then need to
convert the data frame to SpatialPoints using e.g. the function
'SpatialPoints'.

Mathieu.


Le 04/10/2013 10:39 AM, JonathanAronson a écrit :

> perhaps I can clarify my question a lit bit further:
>
> With the adehabitat package I used the function as.kasc to create a single
> data frame with my 15 variables as Ive shown below:
>
> map<- as.kasc(list(bio_01 = var1, bio_12 = var2, Aridity = var3, altitude =
> var4, unpalatable = var5, thicket = var6, succulent = var7, shrubland =
> var8, rainforest = var9, mosaic = var10, mopane = var11, misavanna = var12,
> hydro = var13, fynbos = var14, desert = var15))
>
> However, in the adehabitatHS, what is the equivalent function to use to
> create the data frame which is equivalent to the lynxjura$map spatial pixel
> data frame? There is no as.kasc function. I have used the readAsciiGrid
> function in Maptools but I can only do that individually for each variable.
> How then can I combine these into a single data frame? I have thought of
> using the stack() function in the raster package.
>
> I am really stuck here
> Thanks to anyone who can help
> Jonathan
>
>
>
> --
> View this message in context: http://r-sig-geo.2731867.n2.nabble.com/Help-with-ENFA-in-R-tp7583243p7583272.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
>

--

~$ whoami
Mathieu Basille, PhD

~$ locate --details
University of Florida \\
Fort Lauderdale Research and Education Center
(+1) 954-577-6314
http://ase-research.org/basille

~$ fortune
« Le tout est de tout dire, et je manque de mots
Et je manque de temps, et je manque d'audace. »
  -- Paul Éluard

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: Help with ENFA in R

JonathanAronson
Hi Mathieu

Thank you greatly, I have been using your advice and it seems to be working. I used readAsciiGrid to import my 15 variables and then cbind to create the new data frame. The result is below:

> join <- cbind(x@data, y@data, a@data, b@data, c@data, d@data, e@data, f@data, g@data, h@data, i@data, j@data, k@data, l@data, m@data)
> head(na.omit(join))
    bio_01.asc bio_12.asc Aridity.asc altitude.asc unpalatable.asc thicket.asc
385       9626       5698        6272     7.007191        5.282318    3.979096
386       9611       5432        5951     7.903753        5.279835    3.980666
387       9631       5109        5601     5.723457        5.277520    3.982328
388       9623       4859        5474     6.031349        5.275373    3.984080
389       9634       4694        5210     3.238761        5.273394    3.985923
641       9617       5939        6507     7.019991        5.352698    3.956286
    succulent.asc shrubland.asc rainforest.asc mosaic.asc mopane.asc misavanna.asc
385      105.5797     1.1239479       9.631459   4.517803   18.87709      3.094614
386      105.5253     1.1543059       9.638020   4.519337   18.87111      3.095095
387      105.4725     1.1239479       9.644965   4.521014   18.86544      3.095683
388      105.4215     1.1007079       9.652295   4.522834   18.86010      3.096377
389      105.3720     1.0860595       9.660006   4.524796   18.85507      3.097176
641      106.6615     0.6861283       9.535002   4.500543   19.01172      3.083889
    hydro.asc fynbos.asc desert.asc
385  6.274230   107.9704   1.218094
386  6.290221   107.9120   1.152849
387  6.306502   107.8552   1.095933
388  6.323067   107.8001   1.051082
389  6.339908   107.7465   1.022137
641  5.968595   109.1287   1.152849

I then loaded my locality data and converted to SpatialPoints as follows:

locs<- read.csv("Species_Localities/R.blasii.csv", header=T)
library(sp)
xy.sp = SpatialPoints(locs)
summary(xy.sp)
class(xy.sp)

I think now the next step in the ENFA but Im getting a little stuck. Im not sure what "slot" is in the lynxjura example. Id like to prepare the data for enfa and run the PCA. could you please provide some help with this?

Thank you so so much
Jonathan
Reply | Threaded
Open this post in threaded view
|

Re: Help with ENFA in R

JonathanAronson
Hi there

I have been working on this over the weekend. I have managed to make some progress.
Now I am trying to run the enfa using this code: enfa(pc, pr, scan=FALSE).

I can define pc using my text file of the locality data for my species using this code: pc <- dudi.pca(locs, scannf=FALSE). However, now I need to define pr and Im not sure if that refers to my environmental data. The error I get is below. How can I create the pr vector?

Error in is.vector(pr) : object 'pr' not found

Any help would be greatly appreaciated

Thanks all
Jonathan
Reply | Threaded
Open this post in threaded view
|

Re: Help with ENFA in R

Alexandre Villers-2
Hi,

Typing ?enfa (after loading adehabitatHS) and searching through the
examples that are provided, you should find these lines

## We prepare the data for the ENFA
tab <- slot(map, "data")
pr <- slot(count.points(locs, map), "data")[,1]

Maybe you could start with this, i.e. understanding how the pr object is
obtained, playing with the example.
And then, if you really don't get it, ask someone on the list to help you.

HTH

Alex


On 15/04/2013 12:39, JonathanAronson wrote:

> Hi there
>
> I have been working on this over the weekend. I have managed to make some
> progress.
> Now I am trying to run the enfa using this code: enfa(pc, pr, scan=FALSE).
>
> I can define pc using my text file of the locality data for my species using
> this code: pc <- dudi.pca(locs, scannf=FALSE). However, now I need to define
> pr and Im not sure if that refers to my environmental data. The error I get
> is below. How can I create the pr vector?
>
> Error in is.vector(pr) : object 'pr' not found
>
> Any help would be greatly appreaciated
>
> Thanks all
> Jonathan
>
>
>
> --
> View this message in context: http://r-sig-geo.2731867.n2.nabble.com/Help-with-ENFA-in-R-tp7583243p7583315.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
>
>

--

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: Help with ENFA in R

Alexandre Villers-2
In reply to this post by JonathanAronson
Hi,

Typing ?enfa (after loading adehabitatHS) and searching through the
examples that are provided, you should find these lines

## We prepare the data for the ENFA
tab <- slot(map, "data")
pr <- slot(count.points(locs, map), "data")[,1]

Maybe you could start with this, i.e. understanding how the pr object is
obtained, playing with the example.
And then, if you really don't get it, ask someone on the list to help you.

HTH

Alex


On 15/04/2013 12:39, JonathanAronson wrote:

> Hi there
>
> I have been working on this over the weekend. I have managed to make some
> progress.
> Now I am trying to run the enfa using this code: enfa(pc, pr, scan=FALSE).
>
> I can define pc using my text file of the locality data for my species using
> this code: pc <- dudi.pca(locs, scannf=FALSE). However, now I need to define
> pr and Im not sure if that refers to my environmental data. The error I get
> is below. How can I create the pr vector?
>
> Error in is.vector(pr) : object 'pr' not found
>
> Any help would be greatly appreaciated
>
> Thanks all
> Jonathan
>
>
>
> --
> View this message in context: http://r-sig-geo.2731867.n2.nabble.com/Help-with-ENFA-in-R-tp7583243p7583315.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
>
>

--

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: Help with ENFA in R

JonathanAronson
In reply to this post by Alexandre Villers-2
Hi Alexandre

I have looked at the examples already and those in SP package too before I posted my question.
When I run this line of code from the example: pr <- slot(count.points(locs, join), "data")[,1], I get the following error:

Error in count.points(locs, join) :
  w should inherit the class SpatialPixels

So I am trying to coerce my object "join" from a spatialgriddataframe to a spatialpixeldataframe. However, I have used this code to do that which I found in help examples: test <- as(join, "SpatialPixels")

I get this error:

Error in as(join, "SpatialPixels") :
  no method or default for coercing “data.frame” to “SpatialPixels”

So I cant convert my "join" data frame in the spatial pixels I  need to get the pr object. Ive tried updating my SP package but it still didnt work after that. In the SP package vignette it says that, with reference to SpatialPixels and SpatialGrids: "Objects can be coerced from one representation to the other" but I get the above mentioned error when I try do this.

Thanks
Jonathan
Reply | Threaded
Open this post in threaded view
|

Re: Help with ENFA in R

JonathanAronson
Hi there
I have managed to preapre my data finally to do the enfa. However, when I run the test I get an error and warning message shown below:

ENFA <- enfa(pc, pr, scannf = FALSE)
Error in crossprod(Ze, DpZ) : non-conformable arguments
In addition: Warning messages:
1: In x * pr :
  longer object length is not a multiple of shorter object length
2: In x * pr :
  longer object length is not a multiple of shorter object length
3: In x * pr :
  longer object length is not a multiple of shorter object length
4: In x * pr :
  longer object length is not a multiple of shorter object length

Im not sure what this means. I thought there could be a mismatch between my locality points and the environmental maps but Ive plotted the points and they are in the correct locations. Has anyone encountered this before and can you please provide some advice about how to deal with it.

Thank you Clement, Mathieu and Alex for your help thus far!!

Jon
Reply | Threaded
Open this post in threaded view
|

Re: Help with ENFA in R

Mathieu Basille-2
Jonathan,

I think you are confusing many aspects here...

The ENFA works on two objects:
* a PCA, which provides the environmental data;
* a vector, which provides the utilization distribution.

1) The PCA is build on the "data" slot of a SpatialPixelsDataFrame, which
stores all environmental rasters. The "data" slot that we use is itself of
class 'data.frame'.

2) The utilization distribution is based on the presence points and is also
stored in a SpatialPixelsDataFrame, which gives the number of points per
pixel. Again, the ENFA only uses the "data" slot of this
SpatialPixelsDataFrame. Such map can be created with 'count.points' on a
object of class SpatialPoints or SpatialPointsDataFrame, and also requires
the former SpatialPixelsDataFrame which stores the environmental attributes
(this is just to provide a grid for the 'count.points' function).

Please check every object at each step, and provide reproducible examples
in case you don't manage to get it work. The examples + vignettes of both
adehabitatHS and sp are in principle sufficient to run an ENFA without any
problem.

Best of luck,
Mathieu Basille.


Le 04/16/2013 09:59 AM, JonathanAronson a écrit :

> Hi there
> I have managed to preapre my data finally to do the enfa. However, when I
> run the test I get an error and warning message shown below:
>
> ENFA <- enfa(pc, pr, scannf = FALSE)
> Error in crossprod(Ze, DpZ) : non-conformable arguments
> In addition: Warning messages:
> 1: In x * pr :
>    longer object length is not a multiple of shorter object length
> 2: In x * pr :
>    longer object length is not a multiple of shorter object length
> 3: In x * pr :
>    longer object length is not a multiple of shorter object length
> 4: In x * pr :
>    longer object length is not a multiple of shorter object length
>
> Im not sure what this means. I thought there could be a mismatch between my
> locality points and the environmental maps but Ive plotted the points and
> they are in the correct locations. Has anyone encountered this before and
> can you please provide some advice about how to deal with it.
>
> Thank you Clement, Mathieu and Alex for your help thus far!!
>
> Jon
>
>
>
> --
> View this message in context: http://r-sig-geo.2731867.n2.nabble.com/Help-with-ENFA-in-R-tp7583243p7583325.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
>

--

~$ whoami
Mathieu Basille, PhD

~$ locate --details
University of Florida \\
Fort Lauderdale Research and Education Center
(+1) 954-577-6314
http://ase-research.org/basille

~$ fortune
« Le tout est de tout dire, et je manque de mots
Et je manque de temps, et je manque d'audace. »
  -- Paul Éluard

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo