Coder Social home page Coder Social logo

kenkellner / pyunmarked Goto Github PK

View Code? Open in Web Editor NEW
2.0 3.0 1.0 11 KB

A Python port of the R package unmarked, for analyzing ecological data while accounting for imperfect detection.

License: MIT License

Python 100.00%
n-mixture occupancy hierarchical-models python

pyunmarked's Introduction

pyunmarked

A python port of the R package unmarked, for analyzing ecological data while accounting for imperfect detection.

Fit an occupancy model

import numpy as np
import pandas as pd
from scipy.special import expit
from pyunmarked import OccupancyModel, UnmarkedFrame

# Simulate an occupancy dataset
N = 1000 # Number of sites
J = 5 # Number of sampling occasions

# Occupancy probability parameters
beta_occ = np.array([0, 0.5])
# Occupancy covariate
elev = np.random.randn(N).reshape(N,1)
# Model matrix
mm_occ = np.concatenate([np.repeat(1, N).reshape(N,1), elev], axis=1)
# Occupancy probability
psi = expit(np.matmul(mm_occ, beta_occ))

# Simulate true latent state
z = np.random.binomial(1, psi, N)

# Detection probability parameters
beta_p = np.array([0, -0.4])
# Detection covariate
wind = np.random.randn(N*J).reshape(N*J, 1)
# Model matrix
mm_det = np.concatenate([np.repeat(1,N*J).reshape(N*J,1), wind], axis=1)
# Detection probability
p = expit(np.matmul(mm_det, beta_p)).reshape(N, J)

# Simulate detection process
y = np.empty((N,J)) # presence-absence data matrix
for i in range(N):
    for j in range(J):
        y[i,j] = np.random.binomial(1, z[i]*p[i,j], 1)

# Organize covariates into DataFrames
sc = pd.DataFrame({"elev": elev.reshape(N,)})
oc = pd.DataFrame({"wind": wind.reshape(N*J,)})

# Create UnmarkedFrame containing y and covariates
umf = UnmarkedFrame(y, sc, oc)

# Fit occupancy model
mod = OccupancyModel("~wind", "~elev", umf)
mod.fit()

# Look at summary of output
mod.summary()

# Calculate predicted occupancy at each site
mod.predict("occ")

pyunmarked's People

Contributors

kenkellner avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

juniorq1995

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.