R/R2MCDS-internal.R

Defines functions .abundancetable .chisquaretable .detectiontable .modeltable

.abundancetable <-
function(model){
        #extract lambda value, se and ci
        lambda.val <-round(coef(model, type="state"),3)
        lambda.se<- round(SE(model, type="state"),3)
        lambda.ci <- round(confint(model, type="state"),3)
        #extract pred values
        predicted<-round(unlist(predict(model, type="state")[1,]),3)
        estimates<-c(lambda.val, predicted[1])
        se <- c(lambda.se, predicted[2])
        coef.var <- round(se/estimates*100,3)
        down.CI<- c(lambda.ci[1], predicted[3])
        up.CI<- c(lambda.ci[2], predicted[4])
        #combine all values in a dataframe
        out<-data.frame(estimates, se, coef.var, down.CI, up.CI)
        names(out) <- c("Estimates", "SE*", "% of var.", "95% Lower", "95% Upper")    
        row.names(out)<-c("lambda", "Density")
        return(out)
        #END of the function
        }
.chisquaretable <-
function(model){
          breaks.values<-model@data@dist.breaks
          cuts <- paste(breaks.values[-length(breaks.values)], breaks.values[-1], sep="-")
          #extract observed values
          observed <-colSums(getY(model@data))
          #extract predicted values
          predicted <-colSums(fitted(model))
          #Calculate chi-square values
          chi.values <- (observed - predicted)^2 / predicted 
          out<-data.frame(cuts,observed, predicted, chi.values) 
          return(out)
          #END of the function
          }
.detectiontable <-
function(model){
        d.val <-round(coef(model, type="det"),3)
        d.se<- round(SE(model, type="det"),3)
        d.ci <- round(confint(model, type="det"),3)
        predicted<-round(unlist(predict(model, type="det")[1,]),3)
        effect.half <- round(sapply(1:4, function(i){integrate(gxhn, 0, max(model@data@dist.breaks), sigma=predicted[i])$value }),3)[-2]
        effect.se <-round(((effect.half[1]-effect.half[2])/((predicted[1]-predicted[3])/predicted[2])+(effect.half[3]-effect.half[1])/((predicted[4]-predicted[1])/predicted[2]))/2,3)
        detection  <- round(effect.half/max(model@data@dist.breaks),3)
        detection.se <-round(((detection[1]-detection[2])/((predicted[1]-predicted[3])/predicted[2])+(detection[3]-detection[1])/((predicted[4]-predicted[1])/predicted[2]))/2,3)    
        estimates<-c(d.val, detection[1], effect.half[1])
        se <- c(d.se, detection.se, effect.se)
        coef.var <- round(se/estimates*100,3)
        down.CI<- c(d.ci[1], detection[2], effect.half[2])
        up.CI<- c(d.ci[2], detection[3], effect.half[3])
        out<-data.frame(estimates, se, coef.var, down.CI, up.CI)
        names(out) <- c("Estimates", "SE*", "% of var.", "95% Lower", "95% Upper")
        if(model@keyfun=="halfnorm"){param="sigma"}
        if(model@keyfun=="exp"){param="rate"}
        if(model@keyfun=="hazard"){param="shape"}        
        row.names(out)<-c(param, "p_hat", "EHWS")
        return(out)
        #END of the function
        }
.modeltable <-
function(model, sampling.units="Watches", obs.units="Birds"){
  if(model@data@unitsIn=="m"){
      effort = sum(model@data@tlength)/1000
      diameter  =max(model@data@dist.breaks)
  }else{
      effort  = sum(model@data@tlength)
      diameter = max(model@data@dist.breaks)*1000
  }     
    samples <- nrow(getY(model@data))
    observations <- sum(getY(model@data))
    if(model@keyfun=="halfnorm"){key = "Halfnormal"}
    if(model@keyfun=="exp"){key = "Exponential"}
    if(model@keyfun=="hazard"){key = "Hazard"}
    Descriptive<-c("Effort", " Samples", "Width", "# Observations","Key")  
    Values<-rbind(effort, samples, diameter, observations, key, deparse.level = 0)
    units <- c("km", sampling.units, "m",obs.units, "")
    out<-data.frame(Descriptive, Values, units)
    return(out)
    #END of the function
    }
.Random.seed <-
c(403L, 2L, 809312574L, -1635933832L, -354641317L, -1667060295L, 
2098679816L, -38292810L, -1067480591L, -871251933L, 1597702258L, 
-1458068796L, 131781767L, -1030379427L, 707800660L, -33371014L, 
-1301276731L, 1873418527L, 1775524006L, -542787024L, -1737588525L, 
2038402801L, 1449455136L, -736307010L, 1341373641L, 237713019L, 
1633006666L, 1868537004L, -560968785L, -1118064795L, 1323795740L, 
-661549710L, -237255187L, 515131943L, -315807154L, -1175589208L, 
-929258325L, 1489569225L, 1581976024L, -223977338L, -709300895L, 
-676110093L, 1469124450L, -1451136556L, 589634775L, -1089741107L, 
1040881252L, -1503849398L, 60465589L, 1821551887L, 598575638L, 
-347372352L, -626212221L, -821424479L, -2029191024L, 1001761646L, 
790246681L, 1149470123L, 642745242L, 1215109980L, -847234465L, 
415916597L, -369628724L, -939368158L, 1147790205L, 1461502071L, 
419988894L, -1104626600L, -46503493L, -1651036327L, -1470559000L, 
140924182L, -1092270447L, -979367101L, -929638830L, 1279637732L, 
-1130386649L, 84696957L, 903541364L, -1565496230L, 1777071269L, 
-986804545L, -2074282682L, 539376592L, -1624041997L, 735846673L, 
375500096L, 1903357214L, 1896323561L, -1293214949L, -829749974L, 
-2146279860L, -1784583665L, -189813435L, -750702852L, -934984366L, 
-2145228083L, 1676018311L, -2039331474L, -1162838200L, 829279051L, 
-618122583L, 464336888L, -611739866L, 411713L, -2117572141L, 
-2147286142L, -1944688716L, -530251977L, 875058733L, 41805636L, 
900617322L, -1304129835L, 29280367L, 197986678L, 649540256L, 
1727209315L, 72643585L, 895254384L, -1199294706L, -148557447L, 
-712325877L, 2088132154L, -1349348036L, 1578670719L, -127335979L, 
-1565073428L, 1452622146L, -550568291L, -1887282409L, -1307620738L, 
248224312L, -2038899429L, 1773439609L, -1969125688L, -67723530L, 
268728113L, -505417885L, -2033121998L, -123382140L, 1513046727L, 
-780852835L, -112630508L, -648303686L, -982114811L, 894033887L, 
211768934L, -1398242832L, -1356787949L, -1928359759L, -2005847200L, 
-451288834L, -1670623095L, 669155259L, 986319242L, 686471276L, 
751262191L, 1850905125L, 1166657244L, -1528800078L, 978595757L, 
1445147495L, -1970679666L, -384455320L, -1965314709L, 1739751177L, 
-178777704L, -1989281594L, 1992460833L, 10146483L, 1349050402L, 
-1077298668L, -126321001L, -730959731L, -81984092L, 1727760266L, 
-437623819L, -2034972081L, 1940049238L, 1281124352L, -491964093L, 
624784609L, 557993552L, 813617838L, -871221671L, -2041840021L, 
880079834L, 510076060L, -1477071201L, 467756277L, -2115041908L, 
1371275362L, 1868206141L, 1931512503L, 1148563806L, -418613096L, 
999293947L, 493400473L, 241472040L, -1893260586L, 1225246545L, 
-1908676093L, -1844765294L, -371037404L, 1357532647L, 608193085L, 
-602291020L, -1570585830L, -1020483483L, 443646207L, -993971834L, 
-1752373488L, -1861098573L, -260038575L, -476204032L, 1953772766L, 
-1201780951L, -1969923365L, -832130582L, -464979572L, 1226899151L, 
-2121530747L, -1579165380L, -507001838L, -352326899L, -1073481657L, 
1185782318L, 1470464904L, 1984646795L, -254457760L, -1545150132L, 
69019424L, -1275630974L, -1374262808L, -1284697108L, 969539132L, 
-1170072974L, -608215184L, -1460637404L, -23761352L, -1134617190L, 
-1167247920L, -2136239684L, 240222868L, 1371788930L, -1723870784L, 
-1858560196L, 312637072L, 723612450L, -1985239544L, -1700612340L, 
-1087998052L, 252133394L, -1856363648L, 831815444L, 1612007720L, 
-310026182L, -1245849648L, -1954805140L, 620547124L, 2031531154L, 
1997520224L, -1386786484L, 79309280L, 1416978338L, -627740760L, 
-704236404L, 1073845180L, -1469450126L, -623766544L, -316211132L, 
-1409059752L, -2084302790L, -371171216L, -909405636L, -599672044L, 
1295310530L, -480502048L, -53865348L, 1953628368L, -2112007262L, 
1450447400L, 1360028940L, -692995140L, 1876706610L, -1505047360L, 
232390196L, 1918990024L, 532502202L, 1280311440L, -780420372L, 
-1343411628L, 1102671506L, -1150051552L, -1745376308L, 1465826528L, 
-907105598L, 1742889000L, 1681001388L, 1089780412L, -1598200334L, 
1954530864L, 1741778852L, 1774814648L, 285400922L, -526919536L, 
-1803719812L, -1571626220L, -534994622L, 415826688L, 570879932L, 
1967403856L, 1703965986L, -1460658616L, 1340303372L, -1420537764L, 
-63030830L, 1102690816L, -816717484L, 631629032L, -2004837126L, 
56170192L, -362754772L, 290482420L, 467367314L, 1076074848L, 
-347850740L, -417661216L, -1284408734L, -1571217752L, -869575092L, 
-341853316L, -1553976014L, 862027376L, -1123452092L, 2117997528L, 
335191930L, -97586640L, 920030140L, 565387860L, 1588055106L, 
-1565648736L, 953270972L, -1119871536L, 1855821666L, -1949379864L, 
-542530356L, 770682364L, -560834062L, -623266176L, -1082726924L, 
-1772072312L, -1657026758L, 1709973328L, 2122959980L, 420490644L, 
-353104814L, 1919982048L, 422433996L, 2064904352L, 965945730L, 
77871336L, -708713748L, -2032569028L, -1697084302L, 1473938544L, 
-1122735068L, -895360968L, -1877112038L, 1010941136L, -2086814916L, 
1401333652L, 506408834L, -107489856L, -1634246084L, 1773107600L, 
-1873569246L, 1755933960L, -1304683892L, 888649500L, 1649692818L, 
-508337792L, 2129150484L, -195214552L, 1904174650L, -1647281712L, 
-1620396692L, -2035870796L, 1803516946L, 837349856L, -709590068L, 
2026352864L, 1577248802L, 1829870888L, -992774644L, -1838636228L, 
1985762290L, -1146708240L, -1333884348L, 1912933976L, -999140550L, 
437932528L, 1897602748L, 1664793876L, -1433190718L, -1118011296L, 
1976289148L, 2054773712L, 603176226L, -2049735000L, 660106124L, 
1871740092L, -1401805006L, -188100032L, 2121038004L, 638831176L, 
938335674L, 2081411600L, 320904940L, -598471340L, 1474024722L, 
-575211104L, -1877172532L, -1206516128L, 1705546690L, -1030159576L, 
-1497048148L, -927166660L, -1437966990L, 1741819696L, -2105633500L, 
-1434477768L, 226066138L, 444031888L, -912868612L, 1291342740L, 
320442434L, 1009090816L, -1311329220L, 396395856L, -579993438L, 
2061155656L, 1907358476L, 187949788L, -1598373550L, 1507885184L, 
-2111738796L, -450315288L, -1246292742L, 1361256272L, -658870484L, 
627383668L, -2023981166L, -694174624L, 595916172L, -930198688L, 
-1208545813L, 1131081436L, 1213111050L, 1899632127L, -1232901047L, 
744099294L, 1376214412L, 355707229L, -743145113L, 1479000720L, 
-524755794L, 1248333147L, -883003075L, 1557666730L, 773999688L, 
-1512917903L, -424033821L, 1971297508L, 1163085842L, -1728812057L, 
-1266101327L, 1001565686L, -1448095724L, -414515419L, -681629649L, 
-137498136L, 307185350L, 1079379827L, -534175787L, 203806642L, 
843190656L, -1512855191L, 1940700635L, 1242821932L, 268697402L, 
-1830161937L, -148306823L, 304248590L, 414823132L, 2011550029L, 
-684585801L, 1769543232L, -1480902882L, 468897259L, -25824915L, 
1552125914L, -644769384L, -1882937343L, -314668621L, 943177940L, 
744556002L, 413487223L, 919958977L, -1284972730L, -2056902012L, 
-773598155L, -201567201L, -1794378888L, 658291286L, -1431632157L, 
1257709733L, 954167618L, -1741146320L, -46447783L, -1937913653L, 
710424892L, 1872557418L, 171769759L, 596740649L, -1601186626L, 
1882312108L, 1971974909L, 914243143L, -1821319888L, 235515470L, 
-887169413L, -703779363L, 11373578L, -2012631768L, 625386385L, 
193377667L, -2104323452L, 1403588786L, -1509756921L, -1329238959L, 
-1654948906L, -588578124L, 1264952005L, 2082604047L, 708158600L, 
85001638L, 1344228691L, 352028341L, 227523602L, 1996512736L, 
-1261223863L, 169059963L, 1757245260L, -1560024358L, 137359055L, 
-1591828839L, 1423360686L, -2080563268L, 1148397613L, 584849367L, 
1488182816L, 89096062L, -1039384245L, -194935987L, -2147483270L, 
2041738168L, -611522207L, -1883802349L, -193422028L, -2039773374L, 
-2067589289L, -425376095L, 794257254L, 1011040612L, 1536148629L, 
-1529229889L, 1100853592L, -18145418L, 481439107L, 780076997L, 
-1306641182L, 1040976208L, 1473763449L, 1034181547L, -38993636L, 
595183178L, -933608897L, 1382487689L, 1589723806L, -282927284L, 
323950365L, 1199896231L, 1045511632L, -1353063058L, 203593755L, 
419346813L, 1065049962L, 1562937864L, -1069486415L, -652449501L, 
587143716L, 148181202L, 1727760679L, 1197908849L, 1315557814L, 
1409018196L, -1197094939L, -595349009L, -1392805592L, -481275514L, 
-1703993933L, -162217707L, 1225585522L, -1283194944L, -1452216279L, 
237972635L, 1517988204L, 1436942714L, -1177529681L, 1550019001L, 
970060750L, -2020332772L, -652852595L, -862483721L, -1470096677L
)
RoyChristian/GeoAviR documentation built on Jan. 13, 2020, 8:16 p.m.