How to generate new distributions in packages "distr", "distrex"

Similar documents
R Based Probability Distributions

Special Discrete RV s. Then X = the number of successes is a binomial RV. X ~ Bin(n,p).

robkalman a package on Robust Kalman Filtering

robkalman a package on Robust Kalman Filtering

Package Delaporte. August 13, 2017

R: A Quick Reference

Outline. Unit 3: Inferential Statistics for Continuous Data. Outline. Inferential statistics for continuous data. Inferential statistics Preliminaries

AMS 132: Discussion Section 2

DISCRETE RANDOM VARIABLES EXCEL LAB #3

Classical setup: Linear state space models (SSMs) robkalman a package on Robust Kalman Filtering. Classical setup: Linear state space models (SSMs)

1 Probability Distributions

Sampling Inspection. Young W. Lim Wed. Young W. Lim Sampling Inspection Wed 1 / 26

Outline PMF, CDF and PDF Mean, Variance and Percentiles Some Common Distributions. Week 5 Random Variables and Their Distributions

Epidemiology Principle of Biostatistics Chapter 11 - Inference about probability in a single population. John Koval

The Normal Distribution

STAT100 Elementary Statistics and Probability

Package skellam. R topics documented: December 15, Version Date

Chapter 4 - Lecture 3 The Normal Distribution

Mark Scheme (Results) June 2008

Probability theory and inference statistics! Dr. Paola Grosso! SNE research group!! (preferred!)!!

STAT 135 Lab 5 Bootstrapping and Hypothesis Testing

Chapter 3. Chapter 3 sections

On ARL-unbiased c-charts for i.i.d. and INAR(1) Poisson counts

A Probability Primer. A random walk down a probabilistic path leading to some stochastic thoughts on chance events and uncertain outcomes.

Generalized Bayesian Inference with Sets of Conjugate Priors for Dealing with Prior-Data Conflict

CDA6530: Performance Models of Computers and Networks. Chapter 2: Review of Practical Random Variables

Analysis of 2x2 Cross-Over Designs using T-Tests

Lecture 2: Repetition of probability theory and statistics

Inference for Binomial Parameters

STAT2201 Assignment 3 Semester 1, 2017 Due 13/4/2017

+ Specify 1 tail / 2 tail

Department of Statistical Science FIRST YEAR EXAM - SPRING 2017

Package pearson7. June 22, 2016

Frequency Analysis & Probability Plots

Using the ClassPad300Plus in Statistics to Draw Step Functions and to Compute their Quantiles (Workshop) Ludwig Paditz, University of Applied

Lecture 09: Sep 19, Randomness. Random Variables Sampling Probability Distributions Caching. James Balamuta STAT UIUC

STT 315 Problem Set #3

Findings from a Search for R Spatial Analysis Support. Donald L. Schrupp Wildlife Ecologist Colorado Division of Wildlife (Retired)

Dennis Bricker Dept of Mechanical & Industrial Engineering The University of Iowa

ECE Lecture #10 Overview

Package bivariate. December 10, 2018

Chapter 7: Theoretical Probability Distributions Variable - Measured/Categorized characteristic

STAT 516: Basic Probability and its Applications

Using R in 200D Luke Sonnet

This exam is closed book and closed notes. (You will have access to a copy of the Table of Common Distributions given in the back of the text.

Preliminary Statistics. Lecture 3: Probability Models and Distributions

Week 1 Quantitative Analysis of Financial Markets Distributions A

MARK SCHEME for the October/November 2012 series 9709 MATHEMATICS. 9709/73 Paper 7, maximum raw mark 50

The Chi-Square Distributions

Economics Applied Econometrics II

Introducing the Normal Distribution

(Re)introduction to Statistics Dan Lizotte

Time: 1 hour 30 minutes

Package goftest. R topics documented: April 3, Type Package

Chapter 3 sections. SKIP: 3.10 Markov Chains. SKIP: pages Chapter 3 - continued

The Chi-Square Distributions

CDA6530: Performance Models of Computers and Networks. Chapter 2: Review of Practical Random

3 Modeling Process Quality

Introduction to Probability and Statistics (Continued)

Python. chrysn

Statistics/Mathematics 310 Larget April 14, Solution to Assignment #9

Package homtest. February 20, 2015

Package RTransferEntropy

CS 160: Lecture 16. Quantitative Studies. Outline. Random variables and trials. Random variables. Qualitative vs. Quantitative Studies

Distribution Fitting (Censored Data)

Business Analytics and Data Mining Modeling Using R Prof. Gaurav Dixit Department of Management Studies Indian Institute of Technology, Roorkee

Stat 100a, Introduction to Probability.

Mark Scheme (Results) Summer 2009

Conditional Transformation Models

Lecture 41 Sections Wed, Nov 12, 2008

STA 111: Probability & Statistical Inference

2. Variance and Covariance: We will now derive some classic properties of variance and covariance. Assume real-valued random variables X and Y.

Friedrich-Alexander-Universität. Erlangen-Nürnberg

Bfh Ti Control F Ws 2008/2009 Lab Matlab-1

Introducing the Normal Distribution

CSE 312: Foundations of Computing II Quiz Section #10: Review Questions for Final Exam (solutions)

Transformations of Standard Uniform Distributions

Poisson Chris Piech CS109, Stanford University. Piech, CS106A, Stanford University

EE/CpE 345. Modeling and Simulation. Fall Class 9

Pembangkitan Bilangan Acak dan Resampling

Lecture 2: Some basic principles of the b-calculus

Ten Z-Test Routines from Gopal Kanji s 100 Statistical Tests

6.001 Recitation 22: Streams

Key Words: Lifetime Data Analysis (LDA), Probability Density Function (PDF), Goodness of fit methods, Chi-square method.

Probability Distributions.

Statistical Concepts. Distributions of Data

Operator manual. Simrad ITI Trawl instrumentation system

functions Poisson distribution Normal distribution Arbitrary functions

arxiv:math/ v2 [math.st] 26 Jun 2007

z and t tests for the mean of a normal distribution Confidence intervals for the mean Binomial tests

Analysis of Experimental Designs

EE/CpE 345. Modeling and Simulation. Fall Class 10 November 18, 2002

Bernoulli and Binomial

Power analysis examples using R

Chapter 2. 1 From Equation 2.10: P(A 1 F) ˆ P(A 1)P(F A 1 ) S i P(F A i )P(A i ) The denominator is

Hypothesis testing, part 2. With some material from Howard Seltman, Blase Ur, Bilge Mutlu, Vibha Sazawal

Applied Statistics and Probability for Engineers. Sixth Edition. Chapter 4 Continuous Random Variables and Probability Distributions.

Chapter 4 Continuous Random Variables and Probability Distributions

Chapter 3 sections. SKIP: 3.10 Markov Chains. SKIP: pages Chapter 3 - continued

Transcription:

How to generate new distributions in packages "distr", "distrex" Peter Ruckdeschel Matthias Kohl Institut für Mathematik Fakultät V - Mathematik und Naturwissenschaften Carl von Ossietzky Universität Oldenburg PObox 2503 26111 Oldenburg (Oldb) Germany e-mail: peter.ruckdeschel@uni-oldenburg.de Version control information: Head URL: svn+ssh://ruckdeschel@svn.r-forge. r-project.org/svnroot/distr/pkg/distr/ vignettes/newdistributions.rnw Last changed date: 2011-11-18 12:48:06 +0100 (Fr, 18 Nov 2011) Last changes revision: 753 Version: Revision 753 Last changed by: Peter Ruckdeschel (ruckdeschel) April 22, 2017 Abstract In this vignette, we give short examples how to produce new distributions in packages "distr" and "distrex". This vignette refers to package version 2.6.2. Basically there are three ways to produce new distributions in packages "distr" and "distrex": 1. automatic generation of single distribution objects by arithmetics and the like 2. using generating functions to produce single distribution objects 3. defining new distribution classes / doing it from scratch We will give short examples of all three of them. Universität Oldenburg, Oldenburg FH Furtwangen 1

1 Automatic generation by arithmetics and the like We have made available quite general arithmetical operations to our distribution objects, generating new image distribution objects automatically. As an example, try > require ( d i s t r ) > N Norm(mean = 2, sd = 1. 3 ) > P Pois (lambda = 1. 2 ) > Z 2 N + 3 + P > Z D i s t r i b u t i o n Object o f Class : A b s c o n t D i s t r i b u t i o n > plot (Z, p a n e l. f i r s t = grid ( ), lwd=2) > p(z ) ( 0. 4 ) [ 1 ] 0.002415387 > q(z ) ( 0. 3 ) [ 1 ] 6.705068 > Zs r (Z ) ( 5 0 ) > Zs [ 1 ] 7.528781 5.122758 8.676185 6.753091 5.054000 6.905054 [ 7 ] 7.807627 7.907712 11.610921 7.265653 5.392185 9.991786 [ 1 3 ] 9.684809 4.540207 10.944730 9.727200 4.036700 2.835064 [ 1 9 ] 6.664548 8.802903 3.491921 12.545060 10.673256 13.541608 [ 2 5 ] 6.819095 6.980519 7.038506 6.646279 7.519551 9.259711 [ 3 1 ] 13.210811 5.999851 6.358812 7.282379 9.621614 6.026729 [ 3 7 ] 10.447300 9.302980 6.353487 11.820191 9.041744 5.125658 [ 4 3 ] 3.752013 12.955441 9.524838 8.654323 4.150037 5.601424 [ 4 9 ] 8.688506 2.267838 2

Density of AbscontDistribution CDF of AbscontDistributionQuantile function of AbscontDistrib d(x) 0.00 0.02 0.04 0.06 0.08 0.10 0.12 0.14 p(q) 0.0 0.2 0.4 0.6 0.8 1.0 q(p) 0 5 10 15 20 5 0 5 10 20 x 5 0 5 10 20 q 0.0 0.4 0.8 p Comment: Let N an object of class "Norm" with parameters mean=2, sd=1.3 and let P an object of class "Pois" with parameter lambda=1.2. Assigning to Z the expression 2 N+3+P, a new distribution object is generated of class "AbscontDistribution" in our case so that identifying N, P, Z with random variables distributed according to N, P, Z, L(Z) = L(2 N + 3 + P), and writing p(z)(0.4) we get P (Z 0.4), q(z)(0.3) the 30%-quantile of Z, and with r(z)(50) we generate 50 pseudo random numbers distributed according to Z, while the plot command generates the above figure. There a caveats to take care about; for details refer to the (larger) vignette distr in package "distrdoc". 2 Using generating functions If you want to generate a single distribution object (without any particular parameter) generating functions are the method of choice: Objects of classes LatticeDistribution resp. DiscreteDistribution, AbscontDistribution, may be gen- 3

erated using the generating functions LatticeDistribution () resp. DiscreteDistribution () resp. AbscontDistribution(); see also the corresponding help. E.g., to produce a discrete distribution with support (1, 5, 7, 21) with corresponding probabilities (0.1, 0.1, 0.6, 0.2) we may write > D DiscreteDistribution ( supp = c ( 1, 5, 7, 2 1 ), prob = c (0.1, 0.1, 0.6, 0. 2 ) ) > D D i s t r i b u t i o n Object o f Class : D i s c r e t e D i s t r i b u t i o n > plot (D, p a n e l. f i r s t = grid ( ), lwd = 2) obability function of DiscreteDistr CDF of DiscreteDistributionQuantile function of DiscreteDistrib d(x) 0.0 0.1 0.2 0.3 0.4 0.5 0.6 p(q) 0.0 0.2 0.4 0.6 0.8 1.0 q(p) 5 10 15 20 5 10 15 20 x 0 5 10 20 q 0.0 0.4 0.8 p and to generate an absolutely continuos distribution with density proportional to e x 3, we write > AC AbscontDistribution (d = function ( x ) exp( abs ( x ) 3 ), withstand = TRUE) > AC D i s t r i b u t i o n Object o f Class : A b s c o n t D i s t r i b u t i o n 4

> plot (AC, p a n e l. f i r s t = grid ( ), lwd = 2) Density of AbscontDistribution CDF of AbscontDistributionQuantile function of AbscontDistrib d(x) 0.0 0.1 0.2 0.3 0.4 0.5 p(q) 0.0 0.2 0.4 0.6 0.8 1.0 q(p) 2 1 0 1 2 2 1 0 1 2 x 2 1 0 1 2 q 0.0 0.4 0.8 p 3 Doing it from scratch If you would like to create new parametric distributions, using already implemented r, d, p, and q functions (e.g. implementing additional distributions realized in another CRAN package), you should probably envisage introducing new distribution S4 (sub-)classes and hence better look at the implementation of some discrete and continuous parametric distribution classes in package "distr". Hint: download the.tar.gz file; extract it to some temp folder; look at subdirectories R and man The general procedure is as follows 1. introduce a new subclass of class Parameter 2. introduce a new subclass of LatticeDistribution/DiscreteDistribution (if discrete) or of class AbscontDistribution (if continuous). 5

3. define accessor and replacement functions for the slots of the parameter (e.g. "size" and "prob" in the binomial case), possibly with new generics 4. (possibly) define a validity function 5. define a generating function 6. if existing, define particular convolution methods or similar particular methods for this new distribution class 7. create.rd files for the parameter class distribution class 8. if analytic expressions are available, define particular E-, var-, skewness-, and kurtosis-methods and if so, also document 1 the corresponding methods in the distribution class.rd file Let s go through the steps in the example case of the Binomial implementation in packages "distr" and "distrex": 1. in "distr", see source in R/AllClasses.R, lines 187 196 ## Class: BinomParameter setclass ( BinomParameter, representation = representation ( s i z e = numeric, prob = numeric ), prototype = prototype ( size = 1, prob = 0.5, name = gettext ( Parameter o f a Binomial distribution ) ), c o n t a i n s = Parameter ) #- 2. in "distr", see source in R/AllClasses.R, lines 972 1000 ## Class: binomial distribution setclass ( Binom, prototype = prototype ( r = function (n){ rbinom(n, size = 1,prob = 0. 5 ), d = function ( x, log = FALSE){ dbinom( x, size = 1, prob = 0.5, log = log ), p = function (q, l o w e r. t a i l = TRUE, l o g. p = FALSE ){ pbinom(q, size = 1, prob = 0.5, l o w e r. t a i l = l o w e r. t a i l, l o g. p = l o g. p ), 1 this is new, because so far, all E-, var-, skewness-, and kurtosis-methods for basic distributions are documented in the "distrex" documentation to E, var,..., but this would not be operational any longer for new derived classes, possibly defined in other, new packages 6

q = function (p, l o w e r. t a i l = TRUE, l o g. p = FALSE ){ qbinom(p, size = 1, prob = 0.5, l o w e r. t a i l = l o w e r. t a i l, l o g. p = l o g. p ), img = new( Naturals ), param = new( BinomParameter ), support = 0 : 1, l a t t i c e = new( Lattice, pivot = 0, width = 1, Length = 2, name = gettext ( l a t t i c e o f a Binomial distribution ) ),. l o g E x a c t = TRUE,.lowerExact = TRUE ), c o n t a i n s = LatticeDistribution ) 3. in "distr", see source in R/BinomialDistribution.R, lines 9 16, and 44 54 ## Access Methods setmethod( size, BinomParameter, function ( o b j e c t ) o b j e c t @ s i z e ) setmethod( prob, BinomParameter, function ( o b j e c t ) object@prob ) ## Replace Methods setreplacemethod ( s i z e, BinomParameter, function ( object, value ){ o b j e c t @ s i z e value ; o b j e c t ) setreplacemethod ( prob, BinomParameter, function ( object, value ){ object@prob value ; o b j e c t ) ## wrapped access methods setmethod( prob, Binom, function ( o b j e c t ) prob(param( o b j e c t ) ) ) setmethod( size, Binom, function ( o b j e c t ) size (param( o b j e c t ) ) ) ## wrapped replace methods setmethod( prob, Binom, function ( object, value ) new( Binom, prob = value, size = size ( o b j e c t ) ) ) setmethod( size, Binom, function ( object, value ) new( Binom, prob = prob( o b j e c t ), size = value ) ) and R/AllGenerics, lines 159 162 i f (! isgeneric ( size ) ) setgeneric ( size, function ( o b j e c t ) standardgeneric ( size ) ) i f (! isgeneric ( prob ) ) setgeneric ( prob, function ( o b j e c t ) standardgeneric ( prob ) ) 4. in "distr", see source in R/BinomialDistribution.R, lines 19 33 setvalidity ( BinomParameter, function ( o b j e c t ){ 7

i f ( length (prob( o b j e c t ) )!= 1) stop ( prob has to be a numeric o f length 1 ) i f (prob( o b j e c t ) < 0) stop ( prob has to be in [ 0, 1 ] ) i f (prob( o b j e c t ) > 1) stop ( prob has to be in [ 0, 1 ] ) i f ( length ( size ( o b j e c t ) )!= 1) stop ( s i z e has to be a numeric o f length 1 ) i f ( size ( o b j e c t ) < 1) stop ( size has to be a n a t u r a l g r e a t e r than 0 ) i f (! identical ( floor ( size ( o b j e c t ) ), size ( o b j e c t ) ) ) stop ( size has to be a n a t u r a l g r e a t e r than 0 ) else return (TRUE) ) 5. in "distr", see source in R/BinomialDistribution.R, line 42 Binom function ( size = 1,prob = 0. 5 ) new( Binom, size = size, prob = prob) 6. in "distr", see source in R/BinomialDistribution.R, lines 55 69 ## Convolution for two binomial distributions Bin(n1, p1) and Bin(n2, p2) ## Distinguish cases ## p1 == p2 und p1!= p2 setmethod( +, c ( Binom, Binom ), function ( e1, e2 ){ newsize size ( e1 ) + size ( e2 ) 7. in "distr", see sources in i f (istrue( a l l.equal (prob( e1 ), prob( e2 ) ) ) ) return (new( Binom, prob = prob( e1 ), size = newsize,. w i t h A r i t h = TRUE) ) return ( as ( e1, LatticeDistribution ) + e2 ) ) man/binomparameter-class.rd \name{ BinomParameter class \doctype{ class \ a l i a s {BinomParameter class \ a l i a s { i n i t i a l i z e, BinomParameter method \ t i t l e { C l a s s BinomParameter \ description { The parameter o f a binomial d i s t r i b u t i o n, used by Binom class \ section { Objects from the C l a s s { Objects can be c r e a t e d by c a l l s o f the form \code{new( BinomParameter, prob, s i z e ). Usually an o b j e c t o f t h i s class i s not needed on i t s own, i t i s g enerated 8

a u t o m a t i c a l l y when an o b j e c t o f the class Binom i s i n s t a n t i a t e d. \ section { S l o t s { \ describe { \item{\code{ prob { Object o f class \code{ numeric : the p r o b a b i l i t y o f a binomial d i s t r i b u t i o n \item{\code{ s i z e { Object o f class \code{ numeric : the s i z e o f a binomial d i s t r i b u t i o n \item{\code{name{ Object o f class \code{ character : a name / comment for the parameters \ section { Extends { C l a s s \code{ Parameter, d i r e c t l y. \ section {Methods { \ describe { \item{ i n i t i a l i z e {\code{ s i g n a t u r e (. Object = BinomParameter ) : i n i t i a l i z e method \item{ prob {\code{ s i g n a t u r e ( o b j e c t = BinomParameter ) : r e t u r n s the s l o t \code{ prob o f the parameter o f the d i s t r i b u t i o n \item{ prob {\code{ s i g n a t u r e ( o b j e c t = BinomParameter ) : m o d i f i e s the s l o t \code{ prob o f the parameter o f the d i s t r i b u t i o n \item{ s i z e {\code{ s i g n a t u r e ( o b j e c t = BinomParameter ) : r e t u r n s the s l o t \code{ s i z e o f the parameter o f the d i s t r i b u t i o n \item{ s i z e {\code{ s i g n a t u r e ( o b j e c t = BinomParameter ) : m o d i f i e s the s l o t \code{ s i z e o f the parameter o f the d i s t r i b u t i o n \author{ Thomas Stabla \ email{ statho3@web. de,\ cr F l o r i a n Camphausen \email{fcampi@gmx. de,\ cr Peter Ruckdeschel \email{ p e t e r. ruckdeschel@uni oldenburg. de,\ cr Matthias Kohl \ email{ Matthias. Kohl@stamats. de \ seealso { \code{\ link {Binom class \code{\ link { Parameter class \examples{ W new( BinomParameter, prob=0.5, size =1) s i z e (W) # s i z e of t h i s d i s t r i b u t i o n is 1. s i z e (W) 2 # s i z e of t h i s d i s t r i b u t i o n is now 2. \keyword{ d i s t r i b u t i o n \concept{ parameter \concept{ Binomial d i s t r i b u t i o n \concept{s4 parameter class man/binom-class.rd \name{binom class \doctype{ class 9

\ a l i a s {Binom class \ a l i a s {Binom \ a l i a s { i n i t i a l i z e, Binom method \ t i t l e { C l a s s Binom \ description {The binomial d i s t r i b u t i o n with \code{ s i z e \eqn{= n, by default \eqn{=1, and \code{ prob \eqn{= p, by default \eqn{=0.5, has density \deqn{p ( x ) = {n \choose x {p {x {(1 p ) {n x{ p ( x ) = choose ( n, x ) p x (1 p ) (n x ) for \eqn{x = 0, \ ldots, n. C. f. \ code{\ link [ s t a t s : Binomial ] { rbinom \ section { Objects from the C l a s s { Objects can be c r e a t e d by c a l l s o f the form \code{binom ( prob, s i z e ). This o b j e c t i s a binomial d i s t r i b u t i o n. \ section { S l o t s { \ describe { \item{\code{img { Object o f class \code{ Naturals : The space o f the image o f t h i s d i s t r i b u t i o n has got dimension 1 and the name Natural Space. \item{\code{param{ Object o f class \code{ BinomParameter : the parameter o f t h i s d i s t r i b u t i o n (\ code{ prob, \code{ s i z e ), d e c l a r e d at i t s i n s t a n t i a t i o n \item{\code{ r { Object o f class \code{ function : g e n e r a t e s random numbers ( c a l l s function \code{rbinom) \item{\code{d{ Object o f class \code{ function : density function ( c a l l s function \code{dbinom) \item{\code{p{ Object o f class \code{ function : cumulative function ( c a l l s function \code{pbinom) \item{\code{q{ Object o f class \code{ function : inverse o f the cumulative function ( c a l l s function \code{qbinom ). The quantile i s d e f i n e d as the s m a l l e s t value x such that F( x ) p, where F i s the cumulative function. \item{\code{ support { Object o f class \code{ numeric : a ( s o r t e d ) vector c o n t a i n i n g the support o f the d i s c r e t e density function \item{\code {. witharith { l o g i c a l : used i n t e r n a l l y to i s s u e warnings as to i n t e r p r e t a t i o n o f a r i t h m e t i c s \item{\code {. withsim { l o g i c a l : used i n t e r n a l l y to i s s u e warnings as to accuracy \item{\code {. logexact { l o g i c a l : used i n t e r n a l l y to f l a g the case where t h e r e are e x p l i c i t formulae for the log v e r s i o n o f density, cdf, and quantile function \item{\code {. lowerexact { l o g i c a l : used i n t e r n a l l y to f l a g the case where t h e r e are e x p l i c i t formulae for the lower t a i l v e r s i o n o f c d f and quantile function \item{\code{symmetry{ o b j e c t o f class \code{ DistributionSymmetry ; used i n t e r n a l l y to avoid unnecessary c a l c u l a t i o n s. \ section { Extends { C l a s s \code{ D i s c r e t e D i s t r i b u t i o n, d i r e c t l y. \ cr C l a s s \code{ U n i v a r i a t e D i s t r i b u t i o n, by class \code{ D i s c r e t e D i s t r i b u t i o n. \ cr C l a s s \code{ D i s t r i b u t i o n, by class \code{ D i s c r e t e D i s t r i b u t i o n. \ section {Methods { 10

\ describe { \item{+{\code{ s i g n a t u r e ( e1 = Binom, e2 = Binom ) : For two binomial d i s t r i b u t i o n s with equal p r o b a b i l i t i e s the exact c o n v o l u t i o n formula i s implemented thereby improving the g e n e r a l numerical accuracy. \item{ i n i t i a l i z e {\code{ s i g n a t u r e (. Object = Binom ) : i n i t i a l i z e method \item{ prob {\code{ s i g n a t u r e ( o b j e c t = Binom ) : r e t u r n s the s l o t \code{ prob o f the parameter o f the d i s t r i b u t i o n \item{ prob {\code{ s i g n a t u r e ( o b j e c t = Binom ) : m o d i f i e s the s l o t \code{ prob o f the parameter o f the d i s t r i b u t i o n \item{ s i z e {\code{ s i g n a t u r e ( o b j e c t = Binom ) : r e t u r n s the s l o t \code{ s i z e o f the parameter o f the d i s t r i b u t i o n \item{ s i z e {\code{ s i g n a t u r e ( o b j e c t = Binom ) : m o d i f i e s the s l o t \code{ s i z e o f the parameter o f the d i s t r i b u t i o n \author{ Thomas Stabla \ email{ statho3@web. de,\ cr F l o r i a n Camphausen \email{fcampi@gmx. de,\ cr Peter Ruckdeschel \email{ p e t e r. ruckdeschel@uni oldenburg. de,\ cr Matthias Kohl \ email{ Matthias. Kohl@stamats. de \ seealso { \code{\ link { BinomParameter class \code{\ link { D i s c r e t e D i s t r i b u t i o n class \code{\ link { Naturals class \code{\ link [ s t a t s : Binomial ] { rbinom \examples{ B Binom( prob=0.5, s i z e =1) # B is a b i n o m i a l d i s t r i b u t i o n w i t h p r o b =0.5 and s i z e =1. r (B) ( 1 ) # # one random number generated from this distribution, e. g. 1 d(b) ( 1 ) # D e n s i t y of t h i s d i s t r i b u t i o n is 0.5 for x =1. p(b) ( 0. 4 ) # P r o b a b i l i t y t h a t x < 0. 4 is 0.5. q(b) (. 1 ) # x =0 is the s m a l l e s t v a l u e x s u c h t h a t p ( B )( x ) 0.1. s i z e (B) # s i z e of t h i s d i s t r i b u t i o n is 1. s i z e (B) 2 # s i z e of t h i s d i s t r i b u t i o n is now 2. C Binom( prob = 0.5, s i z e = 1) # C is a b i n o m i a l d i s t r i b u t i o n w i t h p r o b =0.5 and s i z e =1. D Binom( prob = 0.6, s i z e = 1) # D is a b i n o m i a l d i s t r i b u t i o n w i t h p r o b =0.6 and s i z e =1. E B + C # E is a b i n o m i a l d i s t r i b u t i o n w i t h p r o b =0.5 and s i z e =3. F B + D # F is an o b j e c t of c l a s s L a t t i c e D i s t r i b u t i o n. G B + as (D, DiscreteDistribution ) # # D i s c r e t e D i s t r i b u t i o n \keyword{ d i s t r i b u t i o n \concept{ d i s c r e t e d i s t r i b u t i o n \concept{ l a t t i c e d i s t r i b u t i o n \concept{ Binomial family \concept{ Binomial d i s t r i b u t i o n \concept{s4 d i s t r i b u t i o n class \concept{ g e n e r a t i n g function you could have: man/binom.rd for the generating function; in the Binomial case, documentation is in Binom-class.Rd; but in case of the Gumbel distribution, in package "distrex", there is such an extra.rd file 8. in "distrex", see sources in 11

Expectation.R, lines 446 467 setmethod( E, signature ( o b j e c t = Binom, fun = missing, cond = missing ), function ( object, low = NULL, upp = NULL,... ){ i f (! i s. n u l l ( low ) ) i f ( low min( support ( o b j e c t ) ) ) low NULL i f (! i s. n u l l ( upp ) ) i f ( upp max( support ( o b j e c t ) ) ) upp NULL i f ( i s. n u l l ( low ) && i s. n u l l ( upp ) ) return ( size ( o b j e c t ) prob( o b j e c t ) ) else { i f ( i s. n u l l ( low ) ) low Inf i f ( i s. n u l l ( upp ) ) upp I n f i f ( low == Inf ){ i f ( upp == I n f ) return ( size ( o b j e c t ) prob( o b j e c t ) ) else return (m1df( object, upper = upp,... ) ) else { E1 m1df( object, upper = low,... ) E2 i f ( upp == I n f ) size ( o b j e c t ) prob( o b j e c t ) else m1df( object, upper = upp,... ) return (E2 E1) ) Functionals.R, lines 219 230 setmethod( var, signature ( x = Binom ), function ( x,... ){ dots match.call ( c a l l = s y s. c a l l ( sys.parent ( 1 ) ), expand.dots = FALSE)$... fun NULL; cond NULL; low NULL; upp NULL i f (hasarg( low ) ) low dots $low i f (hasarg( upp ) ) upp dots $upp i f (hasarg( fun ) hasarg(cond )! i s. n u l l ( low )! i s. n u l l ( upp ) ) return ( var ( as ( x, DiscreteDistribution ),... ) ) else return ( size ( x ) prob( x ) (1 prob ( x ) ) ) ) skewness.r, lines 69 80 setmethod( skewness, signature ( x = Binom ), function ( x,... ){ dots match.call ( c a l l = s y s. c a l l ( sys.parent ( 1 ) ), expand.dots = FALSE)$... fun NULL; cond NULL; low NULL; upp NULL i f (hasarg( low ) ) low dots $low i f (hasarg( upp ) ) upp dots $upp i f (hasarg( fun ) hasarg(cond )! i s. n u l l ( low )! i s. n u l l ( upp ) ) return ( skewness ( as ( x, DiscreteDistribution ),... ) ) else 12

) return ( ( 1 2 prob( x ) ) /sqrt ( size ( x ) prob( x ) (1 prob ( x ) ) ) ) kurtosis.r, lines 90 102 setmethod( kurtosis, signature ( x = Binom ), function ( x,... ){ dots match.call ( c a l l = s y s. c a l l ( sys.parent ( 1 ) ), expand.dots = FALSE)$... fun NULL; cond NULL; low NULL; upp NULL i f (hasarg( low ) ) low dots $low i f (hasarg( upp ) ) upp dots $upp i f (hasarg( fun ) hasarg(cond )! i s. n u l l ( low )! i s. n u l l ( upp ) ) return ( kurtosis ( as ( x, DiscreteDistribution ),... ) ) else p prob( x ) return ( ( 1 6 p (1 p) ) /( size ( x ) p (1 p) ) ) ) The procedure will be similar for any new class of distributions. Comment In the classes in package "distr" (historically the oldest in the development of this project), we still use initialize methods; this is no longer needed, if you provide generating functions; for this more recent approach, confer the realization of class Gumbel in package "distrex". 4 Help needed / collaboration welcome You are as announced on http://distr.r-forge.r-project.org very welcome to collaborate in this project! See in particular http://distr.r-forge.r-project.org/howto-collaborate.txt With this you should be able to start working. References [1] Ruckdeschel P. and Kohl, M. (2014): General Purpose Convolution Algorithm for Distributions in S4-Classes by means of FFT. J. Statist. Software, 59(4): 1 25. [2] Ruckdeschel P., Kohl M., Stabla T., and Camphausen F. (2006): S4 Classes for Distributions. R-News, 6(2): 10 13. https://cran.r-project.org/doc/rnews/rnews 2006-2.pdf 13