0

I am creating a dataframe of different richness in vegan. I run into trouble with Pielou as I need to log previously created "pumice.richness" data to achieve this result and get error below:

analysis <- function(havreanosim, havre_ANOSIM3.csv)
outfile <- sprintf("%s-analysis.txt", description)
pumice.data<-read.csv("c:\\pumice\\phd\\data_analysis\\havre\\havre_ANOSIM3.csv",header=T)
pumice.locationcode <- pumice.data[, 1:ncol(pumice.data)]
pumice.trop_temp_subtrop <- pumice.data[, 2:ncol(pumice.data)]
pumice.shannon <- specnumber~locationcode(pumice.locationcode, "shannon")
pumice.simpson <- specnumber~locationcode(pumice.locationcode, "simpson")
pumice.richness <- specnumber~locationcode(pumice.locationcode)
pumice.pielou <- pumice.shannon / log(pumice.richness)
Error in log(pumice.richness) : 
  non-numeric argument to mathematical function

I have tried to convert this to a vector as I thought maybe R read this data as a factor using:

as.numeric(levels(f))[f]

But I could not get a result here and perhaps this is not the problem.

Gavin Simpson
  • 170,508
  • 25
  • 396
  • 453

1 Answers1

1

You have some serious misunderstandings of how to call functions in R. Where have you seen calls involving specnumber() that were for the format:

specnumber ~ locationcode(pumice.locationcode, "shannon")

??

You are bolting a formula onto a function call, of some unknown function locationcode.

I genuinely have no idea what you want to do given the mess of code you show, but the source of your problems are clearly that you are forming formula objects in pumice.shannon and pumice.richness and then trying to do mathematical operations on those formula objects.

You also seem to be trying to specnumber() where diversity() is what you appear to need.

This would seem to replicate what you are trying to achieve (using a reproducible example)

data(BCI)
rich <- specnumber(BCI)
shan <- diversity(BCI, "shannon")
shan / log(rich)

which gives:

> shan / log(rich)
        1         2         3         4         5         6         7         8 
0.8865579 0.8685692 0.8476046 0.8752597 0.8602030 0.8500724 0.8706729 0.8729254 
        9        10        11        12        13        14        15        16 
0.8358867 0.8561634 0.8642843 0.8347024 0.8786069 0.8762317 0.8729284 0.8641446 
       17        18        19        20        21        22        23        24 
0.8244489 0.8788828 0.8554245 0.8853802 0.8639438 0.8325271 0.8841064 0.8738548 
       25        26        27        28        29        30        31        32 
0.8755378 0.8751655 0.8661975 0.8314621 0.8281171 0.8419326 0.8575355 0.8453403 
       33        34        35        36        37        38        39        40 
0.8397172 0.8451677 0.5978626 0.8505725 0.8468656 0.7978912 0.7968043 0.7382083 
       41        42        43        44        45        46        47        48 
0.8762204 0.8881987 0.8387881 0.8431126 0.8213811 0.8554539 0.8477709 0.8676229 
       49        50 
0.8377231 0.8618931
Gavin Simpson
  • 170,508
  • 25
  • 396
  • 453