Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update packages R 3.6.3 #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
20 changes: 20 additions & 0 deletions BiasedUrn/DESCRIPTION
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Package: BiasedUrn
Type: Package
Title: Biased Urn Model Distributions
Version: 1.07
Date: 2015-12-28
Author: Agner Fog
Maintainer: Agner Fog <agner@agner.org>
Description: Statistical models of biased sampling in the form of
univariate and multivariate noncentral hypergeometric distributions,
including Wallenius' noncentral hypergeometric distribution and
Fisher's noncentral hypergeometric distribution
(also called extended hypergeometric distribution).
See vignette("UrnTheory") for explanation of these distributions.
License: GPL-3
URL: http://www.agner.org/random/ http://www.r-project.org
Packaged: 2015-12-28 07:10:49 UTC; A
NeedsCompilation: yes
Repository: CRAN
Date/Publication: 2015-12-28 09:01:09
Built: R 3.6.3; x86_64-pc-linux-gnu; 2020-09-23 19:35:30 UTC; unix
4 changes: 4 additions & 0 deletions BiasedUrn/INDEX
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
BiasedUrn Biased Urn Model Distributions
BiasedUrn-Multivariate
Biased urn models: Multivariate distributions
BiasedUrn-Univariate Biased urn models: Univariate distributions
Binary file added BiasedUrn/Meta/Rd.rds
Binary file not shown.
Binary file added BiasedUrn/Meta/demo.rds
Binary file not shown.
Binary file added BiasedUrn/Meta/features.rds
Binary file not shown.
Binary file added BiasedUrn/Meta/hsearch.rds
Binary file not shown.
Binary file added BiasedUrn/Meta/links.rds
Binary file not shown.
Binary file added BiasedUrn/Meta/nsInfo.rds
Binary file not shown.
Binary file added BiasedUrn/Meta/package.rds
Binary file not shown.
Binary file added BiasedUrn/Meta/vignette.rds
Binary file not shown.
41 changes: 41 additions & 0 deletions BiasedUrn/NAMESPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
useDynLib(BiasedUrn)

# Functions in urn1.R
export(dFNCHypergeo)
export(dWNCHypergeo)
export(pFNCHypergeo)
export(pWNCHypergeo)
export(qFNCHypergeo)
export(qWNCHypergeo)
export(rFNCHypergeo)
export(rWNCHypergeo)
export(meanFNCHypergeo)
export(meanWNCHypergeo)
export(varFNCHypergeo)
export(varWNCHypergeo)
export(modeFNCHypergeo)
export(modeWNCHypergeo)
export(oddsFNCHypergeo)
export(oddsWNCHypergeo)
export(numFNCHypergeo)
export(numWNCHypergeo)
export(minHypergeo)
export(maxHypergeo)

# Functions in urn2.R
export(dMFNCHypergeo)
export(dMWNCHypergeo)
export(rMFNCHypergeo)
export(rMWNCHypergeo)
export(momentsMFNCHypergeo)
export(momentsMWNCHypergeo)
export(meanMFNCHypergeo)
export(meanMWNCHypergeo)
export(varMFNCHypergeo)
export(varMWNCHypergeo)
export(oddsMFNCHypergeo)
export(oddsMWNCHypergeo)
export(numMFNCHypergeo)
export(numMWNCHypergeo)
export(minMHypergeo)
export(maxMHypergeo)
27 changes: 27 additions & 0 deletions BiasedUrn/R/BiasedUrn
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# File share/R/nspackloader.R
# Part of the R package, http://www.R-project.org
#
# Copyright (C) 1995-2012 The R Core Team
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# A copy of the GNU General Public License is available at
# http://www.r-project.org/Licenses/

local({
info <- loadingNamespaceInfo()
pkg <- info$pkgname
ns <- .getNamespace(as.name(pkg))
if (is.null(ns))
stop("cannot find namespace environment for ", pkg, domain = NA);
dbbase <- file.path(info$libname, pkg, "R", pkg)
lazyLoad(dbbase, ns, filter = function(n) n != ".__NAMESPACE__.")
})
Binary file added BiasedUrn/R/BiasedUrn.rdb
Binary file not shown.
Binary file added BiasedUrn/R/BiasedUrn.rdx
Binary file not shown.
26 changes: 26 additions & 0 deletions BiasedUrn/demo/ApproxHypergeo.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# ApproxHypergeo.R
# This demo compares a Wallenius' and a Fisher's noncentral hypergeometric
# distribution with the same mean rather than the same odds in order to
# make them approximate each other better.

require(BiasedUrn)
require(stats)

ApproxHypPlot <- function(m1, m2, n, w.odds) {
xmin <- minHypergeo(m1, m2, n)
xmax <- maxHypergeo(m1, m2, n)
x <- xmin : xmax
w.mean <- meanWNCHypergeo(m1, m2, n, w.odds)
f.odds <- oddsFNCHypergeo(w.mean, m1, m2, n)
wnc <- dWNCHypergeo(x, m1, m2, n, w.odds)
fnc <- dFNCHypergeo(x, m1, m2, n, f.odds)
fnc0 <- dFNCHypergeo(x, m1, m2, n, w.odds)
plot (x, fnc, type="l", col="red",
main = "Hypergeometric distributions",
sub = "Blue = Wallenius, Red = Fisher w. same mean,\n Green = Fisher w. same odds",
xlab = "", ylab = "Probability")
points (x, wnc, type="l", col="blue")
points (x, fnc0, type="l", col="green", lty="dashed")
}

ApproxHypPlot(80, 60, 100, 0.5)
25 changes: 25 additions & 0 deletions BiasedUrn/demo/CompareHypergeo.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# CompareHypergeo.R
# This demo shows the difference between the three distributions:
# 1. Wallenius' noncentral hypergeometric distribution
# 2. Fisher's noncentral hypergeometric distribution
# 3. The (central) hypergeometric distribution

require(BiasedUrn)
require(stats)

ComparePlot <- function(m1, m2, n, odds) {
xmin <- minHypergeo(m1, m2, n)
xmax <- maxHypergeo(m1, m2, n)
x <- xmin : xmax
wnc <- dWNCHypergeo(x, m1, m2, n, odds)
fnc <- dFNCHypergeo(x, m1, m2, n, odds)
hyp <- dhyper(x, m1, m2, n)
plot (x, wnc, type="l", col="blue",
main = "Hypergeometric distributions",
sub = "Blue = Wallenius, Red = Fisher, Green = Central",
xlab = "x", ylab = "Probability")
points (x, fnc, type="l", col="red")
points (x, hyp, type="l", col="green")
}

ComparePlot(80, 60, 100, 0.5)
21 changes: 21 additions & 0 deletions BiasedUrn/demo/OddsPrecision.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# OddsPrecision.R
# This demo tests the precision of the odds functions for
# Wallenius' and a Fisher's noncentral hypergeometric distributions
# by calculating the mean of distributions with known odds and then
# estimating the odds from the means.

require(BiasedUrn)
require(stats)

OddsEst <- function(m1, m2, n, odds) {
meanW <- meanWNCHypergeo(m1, m2, n, odds, 1E-9)
oddsEstW <- oddsWNCHypergeo(meanW, m1, m2, n)
meanF <- meanFNCHypergeo(m1, m2, n, odds, 1E-9)
oddsEstF <- oddsFNCHypergeo(meanF, m1, m2, n)
list(Odds=odds, Wallenius.mean = meanW, Fisher.mean = meanF,
Wallenius.estimated.odds = oddsEstW, Fisher.estimated.odds = oddsEstF,
Wallenius.rel.error = (oddsEstW-odds)/odds,
Fisher.rel.error = (oddsEstF-odds)/odds)
}

OddsEst(10, 12, 15, 0.6)
36 changes: 36 additions & 0 deletions BiasedUrn/demo/SampleWallenius.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# SampleWallenius.R
# This demo makes random samples from Wallenius' noncentral hypergeometric
# distribution and compares measured and expected frequencies

require(BiasedUrn)
require(stats)

MakeSamples <- function(m1, m2, n, odds) {
nsamp <- 100000 # Desired number of samples from distribution
xmin <- minHypergeo(m1, m2, n) # Lower limit for x
xmax <- maxHypergeo(m1, m2, n) # Upper limit for x

# Make nsamp samples from Wallenius' distribution
X <- rWNCHypergeo(nsamp, m1, m2, n, odds)

# Get table of frequencies
XTab <- as.data.frame(table(X))

# Relative frequencies
XTab$Freq <- XTab$Freq / nsamp

# Get expected frequencies
XTab$Expected <- dWNCHypergeo(as.integer(levels(XTab$X)), m1, m2, n, odds)

print("X frequencies in Wallenius' noncentral hypergeometric distribution")

# List measured vs. expected frequencies
# (How do I get rid of the row names?)
print(XTab, digits=5)

# Draw histogram
# (Why does my histogram show densities bigger than 1?)
hist(X, freq=FALSE)
}

MakeSamples(6, 8, 5, 1.5)
4 changes: 4 additions & 0 deletions BiasedUrn/demo/UrnTheory.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# UrnTheory.R
# This opens the file UrnTheory.pdf to explain the biased urn models.

vignette("UrnTheory", package="BiasedUrn")
Loading