R/Hs.R

Defines functions Hs

Documented in Hs

Hs <-
function(obs,base=exp(1),corr=FALSE, scrub=TRUE){
				if (scrub==TRUE) obs <- obs[obs>0]
				nsp <- length(obs)
                nsamp <- sum(obs)
                obs = obs/nsamp
                lnobs = obs * 0
                for (k in 1:nsp) {
                  if (obs[k] == 0) {
                    lnobs[k] = 0
                  }
                  else {
                    lnobs[k] = log(obs[k], base)
                  }
                }
                if (corr==FALSE) {H = -sum(obs * lnobs)}
                if (corr==TRUE) {H = -sum(obs * lnobs) - ((nsp-1)/(2*nsamp))}
                return(H)
                }

Try the DiversitySampler package in your browser

Any scripts or data that you put into this service are public.

DiversitySampler documentation built on May 30, 2017, 4:20 a.m.