R/mom_nosource.R

Defines functions mom_nosource

Documented in mom_nosource

#' Method of Moments Estimating of Migration Paramter
#'
#' This function estimates the migration parameter, given only data on a local community.
#' This method is an extension from the paper "Taxa-Abundance Distributions in Microbial Communities Using Environmental
#' Sequence Data" by Sloan et al.
#' @param local A local community of OTU reads. Rows should be OTUs, Columns should be Samples. A column of taxon indexes should be included at the beginning. Note that if this is not included, the first sample in your data will not be used.
#' @import vegan 
#' @return a list of 1 element. Element 1 is the estimate for the migration parameter.
#' @export

mom_nosource <- function(local, meta)
{
  
  NT=sum(local[,2])
  d=1/NT
  
  oralMn=t(t(local[,2])/sum(local[,2]))
  
  lungFr=ifelse(local[,2] == 0, 0, 1)
  
  minFcn <- function(m){
    sum((lungFr-1+pbeta(d,NT*m*oralMn, NT*m*(1-oralMn)))^2)
  }
  
  f1Oral=optimize(f=minFcn,lower=1.0e-7,upper=1-1.0e-7)
  
  return(list(f1Oral$min))
}
kathalexknuts/ntsims documentation built on May 4, 2019, 6:40 p.m.