Giter Site home page Giter Site logo

gq's Introduction

gq

Ryan Gosling, almost as good-looking of a guy as we are

Gaussian quadrature-based integration functions in R. Depends on the statmod package (in fact statmod's gauss.quad function computes the quadrature points and weights). The integration limits can be vectors.

There is no numerical optimization to find the exact answer or to get the answer right within a certain error tolerance - you simply specify the number of points you want to use in the approximation. So this is not the best approach when you need high accuracy. This is more for when you want fast computation over a large number of different limits.

As an example of where you'd want that: we use this to evaluate integrals in likelihood functions. We may have millions of observations, each with a different limit, but in practice it may not adversely affect likelihood maximization too much if the integral is not exactly calculated.

Installation

Clone the repo and run R CMD INSTALL gq.

Usage

> legendreIntegrate(function(x) x^2 + sqrt(x), 1:5, 2:6)
> jacobiIntegrate(function(x) sqrt((1+x)/(1-x)), -1, 1, alpha=0, beta=0)       # inexact
> jacobiIntegrate(function(x) sqrt((1+x)/(1-x)), -1, 1, alpha=-0.5, beta=0.5)  # more exact with proper weight function
> laguerreIntegrate(function(x) exp(-x), c(0, Inf), c(Inf, 0))
> laguerreIntegrate(function(x) exp(x), c(-Inf, 0), c(0, -Inf))

See the documentation and inst/tests/test-gq.R for several examples.

Tests

Tests are written with testthat. You can test the package with test_package.

gq's People

Watchers

Aubrey Holland avatar Jon Pospischil avatar James Cloos avatar Andrew Lim avatar Nick Resnick avatar

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.