The nor1mix Package. June 12, 2007

Similar documents
The nor1mix Package. August 3, 2006

Package nor1mix. August 30, 2017

Package CLA. February 6, 2018

A Handbook of Statistical Analyses Using R. Brian S. Everitt and Torsten Hothorn

Package munfold. R topics documented: February 8, Type Package. Title Metric Unfolding. Version Date Author Martin Elff

STATISTICAL LABORATORY, April 30th, 2010 BIVARIATE PROBABILITY DISTRIBUTIONS

Univariate Data - 2. Numeric Summaries

Univariate Data - 2. Numeric Summaries

Package glogis. R topics documented: March 16, Version Date

Package ICSOutlier. February 3, 2018

Package mixphm. July 23, 2015

Package beanplot. R topics documented: February 19, Type Package

Types of Plotting Functions. Managing graphics devices. Further High-level Plotting Functions. The plot() Function

Package MixSim. April 29, 2017

Package logspline. February 3, 2016

The gld Package. April 6, 2006

Package EnQuireR. R topics documented: February 19, Type Package Title A package dedicated to questionnaires Version 0.

Package tclust. May 24, 2018

Package feature. R topics documented: July 8, Version Date 2013/07/08

Package GLDreg. February 28, 2017

Introduction to RStudio

Package feature. R topics documented: October 26, Version Date

Package uclaboot. June 18, 2003

Statistics 251: Statistical Methods

Package HMMCont. February 19, 2015

Applied Calculus. Lab 1: An Introduction to R

Plotting: An Iterative Process

Graphics in R STAT 133. Gaston Sanchez. Department of Statistics, UC Berkeley

Frequency Distributions

UP School of Statistics Student Council Education and Research

Boxplot

AA BB CC DD EE. Introduction to Graphics in R

Package nplr. August 1, 2015

Package ihs. February 25, 2015

Package mlegp. April 15, 2018

R Programming Basics - Useful Builtin Functions for Statistics

The simpleboot Package

Quality Control-2 The ASTA team

Visual Analytics. Visualizing multivariate data:

Package replicatedpp2w

Chapter 5snow year.notebook March 15, 2018

Package areaplot. October 18, 2017

Package r2d2. February 20, 2015

Stat 290: Lab 2. Introduction to R/S-Plus

Package extremevalues

Package rafalib. R topics documented: August 29, Version 1.0.0

Package evmix. February 9, 2018

Package simed. November 27, 2017

Behavior of the sample mean. varx i = σ 2

Package rknn. June 9, 2015

Package HDInterval. June 9, 2018

Package libstabler. June 1, 2017

R Programming: Worksheet 6

IST 3108 Data Analysis and Graphics Using R Week 9

Teaching univariate measures of location-using loss functions

Package visualizationtools

Package sciplot. February 15, 2013

R is a programming language of a higher-level Constantly increasing amount of packages (new research) Free of charge Website:

Package SCBmeanfd. December 27, 2016

Package NormalLaplace

The supclust Package

Introduction to R. Biostatistics 615/815 Lecture 23

Package MeanShift. R topics documented: August 29, 2016

Date Lesson TOPIC HOMEWORK. Displaying Data WS 6.1. Measures of Central Tendency WS 6.2. Common Distributions WS 6.6. Outliers WS 6.

Note Set 4: Finite Mixture Models and the EM Algorithm

Package spd. R topics documented: August 29, Type Package Title Semi Parametric Distribution Version Date

Package ICEbox. July 13, 2017

ECLT 5810 Data Preprocessing. Prof. Wai Lam

Statistical Programming with R

Az R adatelemzési nyelv

Package diptest. December 5, 2016

AN INTRODUCTION TO LATTICE GRAPHICS IN R

Package pvclust. October 23, 2015

Package pathdiagram. R topics documented: August 29, 2016

Computer exercise 1 Introduction to Matlab.

Package RPMM. August 10, 2010

Package splicegear. R topics documented: December 4, Title splicegear Version Author Laurent Gautier

Package gibbs.met documentation

Matrix algebra. Basics

Package Rramas. November 25, 2017

The som Package. September 19, Description Self-Organizing Map (with application in gene clustering)

Chapter 1. Introduction

Continuous-time stochastic simulation of epidemics in R

Clustering Lecture 5: Mixture Model

Package desire. R topics documented: February 19, Version Title Desirability functions in R

> glucose = c(81, 85, 93, 93, 99, 76, 75, 84, 78, 84, 81, 82, 89, + 81, 96, 82, 74, 70, 84, 86, 80, 70, 131, 75, 88, 102, 115, + 89, 82, 79, 106)

Chapter 5 An Introduction to Basic Plotting Tools

Package SmoothHazard

Package naivebayes. R topics documented: January 3, Type Package. Title High Performance Implementation of the Naive Bayes Algorithm

Package nonmem2r. April 5, 2018

Package abf2. March 4, 2015

Package ParetoPosStable

Regression III: Advanced Methods

Introduction to R. Hao Helen Zhang. Fall Department of Mathematics University of Arizona

STA 570 Spring Lecture 5 Tuesday, Feb 1

Package waterfall. R topics documented: February 15, Type Package. Version Date Title Waterfall Charts in R

Package Daim. February 15, 2013

Use of Extreme Value Statistics in Modeling Biometric Systems

Introduction to R 21/11/2016

Chapter 6: DESCRIPTIVE STATISTICS

Transcription:

The nor1mix Package June 12, 2007 Title Normal (1-d) Mixture Models (S3 Classes and Methods) Version 1.0-7 Date 2007-03-15 Author Martin Mächler Maintainer Martin Maechler <maechler@stat.math.ethz.ch> Onedimensional Normal Mixture Models Classes, for, e.g., density estimation or clustering algorithms research and teaching; providing the widely used Marron-Wand densities, see?marronwand. License GPL 2 Depends R (>= 2.0.0) Encoding latin1 NOTE Use the mclust package for estimation! R topics documented: MarronWand........................................ 2 dnormix........................................... 3 normix........................................... 4 plot.normix......................................... 6 pnormix........................................... 7 r.normix........................................... 8 rnormix........................................... 9 Index 11 1

2 MarronWand MarronWand Marron-Wand Densities as normix Objects The fifteen density examples used in Marron and Wand (1992) s simulation study have been used in quite a few subsequent studies, can all be written as normal mixtures and are provided here for convenience and didactical examples of normal mixtures. Number 16 has been added by Jansen et al. MW.nm1 # Gaussian MW.nm2 # Skewed MW.nm3 # Str Skew MW.nm4 # Kurtotic MW.nm5 # Outlier MW.nm6 # Biomdal MW.nm7 # Separated (bimodal) MW.nm8 # Aymmettric Bimodal MW.nm9 # Trimodal MW.nm10 # Claw MW.nm11 # Double Claw MW.nm12 # Asymmetric Claw MW.nm13 # Asymm. Double Claw MW.nm14 # Smooth Comb MW.nm15 # Discrete Comb MW.nm16 # Distant Bimodal Author(s) Martin Maechler Source The first part are translated from Steve Marron s Matlab code at http://www.stat.unc.edu/ postscript/papers/marron/parameters/nmpar.m References Marron, S. and Wand, M. (1992) Exact Mean Integrated Squared Error; Annals of Statistcs 20, 712 736. For number 16, Janssen, Marron, Verb..., Sarle (1995)...

dnormix 3 MW.nm10 plot(mw.nm14) ## These are defined as normix() calls in../r/zmarrwand-dens.r ppos <- which("package:nor1mix" == search()) nms <- ls(pat="^mw.nm", pos = ppos) nms <- nms[order(as.numeric(substring(nms,6)))] for(n in nms) { cat("\n",n,":\n"); print(get(n, pos = ppos)) } ## Plot all of them: op <- par(mfrow=c(4,4), mgp = c(1.2, 0.5, 0), tcl = -0.2, mar =.1 + c(2,2,2,1), oma = c(0,0,3,0)) for(n in nms) { plot(get(n, pos = ppos))} mtext("the Marron-Wand Densities", outer= TRUE, font= 2, cex= 1.6) ## and their Q-Q-plots (not really fast): prob <- ppoints(n <- 100) for(n in nms) { D <- get(n, pos = ppos) qqnorm(qnormix(d, prob), main = n) } mtext("qq-plots of Marron-Wand Densities", outer = TRUE, font = 2, cex = 1.6) par(op) dnormix Normal Mixture Density Evaluate the density function of the normal mixture specified as normix object. dnormix (x, obj, log = FALSE) dnormixl(obj, x = NULL, log = FALSE, xlim = NULL, n = 511) obj x log an object of class normix. numeric vector with abscissa values where to evaluate the density. For dnormixl() by default, when NULL, it is constructed from n (and xlim if that is specified). logical indicating log-density values should be returned.

4 normix xlim n range of abscissa values, used if x == NULL. By default, xlim is taken as mean plus/minus 3 standard deviations of the normal mixture. number of abscissa values to generate if x is not specified. Value dnormix(x) returns the numeric vector of density values f(x), logged if log is TRUE. dnormixl() returns a list with components x y the abscissa values. the density values f(x) as for dnormix(). See Also rnormix for random number generation, and normix for the construction and further methods, particularly plot.normix which makes use dnormix. ff <- dnormixl(mw.nm7) str(ff) plot(ff, type = "h") # rather use plot(ff,...) normix Mixtures of Univariate Normal Distributions Objects of class normix represent finite mixtures of (univariate) normal (aka Gaussian) distributions. Methods for construction, printing, plotting, and basic computations are provided. normix(mu, sig2 = rep(1,m), w = NULL, name = NULL, long.name = FALSE) is.normix(obj) m.normix(obj) var.normix(x,...) ## S3 method for class 'normix': mean(x,...) ## S3 method for class 'normix': print(x,...)

normix 5 mu sig2 w name long.name obj,x numeric vector of length K, say, specifying the means µ of the K normal components. numeric vector of length K, specifying the variances σ 2 of the K normal components. numeric vector of length K, specifying the mixture proportions π j of the normal components, j = 1,..., K. Defaults to equal proportions optional name tag of the result (used for printing). logical indicating if the name attribute should use punctuation and hence be slightly larger than by default. an object of class normix.... further arguments passed to methods. Details The (one dimensional) normal mixtures, R objects of class "normix", are constructed by normix and tested for by is.normix. m.normix() returns the number of mixture components; the mean() method (for class "normix" returns the mu vector of means and var.normix() (not a method, call the function explicitly!) the sig2 vector of variances. For further methods see below. Value normix returns objects of class "normix" which are currently implemented as 3-column matrix with column names mu, sig2, and w, and further attributes. The user should rarely need to access the underlying structure directly. Note For estimation of the parameters of a normal mixture distribution, I recommend using other R packages, notably package mclust. Author(s) Martin Maechler See Also dnormix for the density, pnormix for the cumulative distribution and the quantile function (qnormix), and rnormix for random numbers and plot.normix, the plot method. MarronWand has the Marron-Wand densities as normal mixtures.

6 plot.normix ex <- normix(mu = c(1,2,5))# s^2 = 1, equal proportions ex plot(ex)# looks like a mixture of only 2 plot(ex, log = "y")# maybe "revealing" plot.normix Plotting Methods for normix Objects The plot and lines methods for normix objects draw the normal mixture density, optionally additonally with a fitted normal density. ## S3 method for class 'normix': plot(x, type = "l", n = 511, xout = NULL, xlim = NULL, xlab = "x", ylab = "f(x)", main = attr(x, "name"), lwd = 1.4, p.norm = TRUE, p.h0 = TRUE, parnorm = list(col = 2, lty = 2, lwd = 0.4), parh0 = list(col = 3, lty = 3, lwd = 0.4),...) ## S3 method for class 'normix': lines(x, type = "l", n = 511, xout = NULL, lwd = 1.4, p.norm = FALSE, parnorm = list(col = 2, lty = 2, lwd = 0.4),...) x object of class normix. type character denoting type of plot, see, e.g. lines. n number of points to generate if xout is unspecified. xout numeric or NULL giving the abscissae at which to draw the density. xlim range of x values to use; particularly important if xout is not specified where xlim is passed to dnormix and gets a smart default if unspecified. xlab,ylab labels for the x and y axis with defaults. main main title of plot, defaulting to the normix name. lwd line width for plotting with a non-standard default. p.norm logical indicating if the normal density with the same mean and variance should be drawn as well. p.h0 logical indicating if the line y = 0 should be drawn. parnorm graphical parameters for drawing the normal density if p.norm is true. parh0 graphical parameters for drawing the line y = 0 if p.h0 is true.... further arguments passed to and from methods.

pnormix 7 Author(s) Martin Maechler See Also normix for the construction and further methods, particularly dnormix which is used here. plot(normix(m=c(0,3),s=c(4,1))) ## Further examples in?normix and?rnormix pnormix Normal Mixture Cumulative Distribution and Quantiles Compute cumulative probabilities or quantiles (the inverse) for a normal mixture specified as normix object. pnormix(q, obj, lower.tail = TRUE, log.p = FALSE) qnormix(p, obj, lower.tail = TRUE, log.p = FALSE, tol =.Machine$double.eps^0.25, maxiter = 1000) obj p q Details lower.tail log.p an object of class normix. numeric vector of probabilities. numeric vector of quantiles logical; if TRUE (default), probabilities are P [X x], otherwise, P [X > x]. logical; if TRUE, probabilities p are given as log(p). tol, maxiter determine the root finding algorithm, see uniroot. Whereas the distribution function pnormix is the trivial sum of weighted normal probabilities (pnorm), its inverse is currently computed numerically using uniroot to find q such that pnormix(obj, q) == p. Value a numeric vector of the same length as p or q, respectively.

8 r.normix Author(s) First version by Erik Jørgensen Erik.Jorgensen@agrsci.dk. See Also dnormix for the density function. MW.nm3 # the "strange skew" one plot(mw.nm3) ## now the cumlative : x <- seq(-4,4, length=1001) plot(x, pnormix(x, MW.nm3), type="l", col=2) ## and some of its inverse : pp <- seq(.1,.9, by=.1) plot(qnormix(pp, MW.nm3), pp) ## The "true" median of a normal mixture: median.normix <- function(x) qnormix(1/2, x) median.normix(mw.nm3) ## -2.32 r.normix Ratio of Normal Mixture to Corresponding Normal Compute r(x) = f(x)/f0(x) where f() is a normal mixture density and f0 the normal density with the same mean and variance as f. r.normix(obj, x = NULL, xlim = NULL, n = 511, xy.return = TRUE) obj x xlim n xy.return an object of class normix. numeric vector with abscissa values where to evaluate the density. Default is constructed from n (and xlim if specified). range of abscissa values, used if x == NULL. By default, xlim taken as mean plus/minus 3 standard deviations of the normal mixture. number of abscissa values to generate if x is not specified. logical indicating if the result should be a list or just a numeric vector, see below.

rnormix 9 Value Note It depends on xy.return. If it s false, a numeric vector of the same length as x, if true (as per default), a list that can be plotted, with components x abscissa values corresponding to argument x. y f0 corresponding values r(x). values of the moment matching normal density f0(x). The ratio function is used in certain semi-parametric density estimation methods (and theory). d3 <- normix(m = 5*(0:2), w = c(0.6, 0.3, 0.1)) plot(d3) rd3 <- r.normix(d3) str(rd3) stopifnot(rd3 $ y == r.normix(d3, xy.ret = FALSE)) par(new = TRUE) plot(rd3, type = "l", col = 3, axes = FALSE, xlab = "", ylab="") axis(4, col.axis=3) rnormix Generate Normal Mixture Distributed Random Numbers Generate n random numbers, distributed according to a normal mixture. rnormix(n, obj) n obj the number of random numbers desired. an object of class normix. Details Value For a mixture of m, i.e., m.normix(obj), components, generate the number in each component as multinomial, and then use rnorm for each. numeric vector of length n.

10 rnormix See Also dnormix for the density, and normix for the construction and further methods. x <- rnormix(5000, MW.nm10) hist(x)# you don't see the claw plot(density(x), ylim = c(0,0.6), main = "Estim. and true 'MW.nm10' density") lines(mw.nm10, col = "orange")

Index Topic datasets MarronWand, 1 Topic distribution dnormix, 3 MarronWand, 1 normix, 4 plot.normix, 5 pnormix, 6 r.normix, 8 rnormix, 9 Topic hplot plot.normix, 5 class, 4 dnormix, 3, 5 7, 9 dnormixl (dnormix), 3 is.normix (normix), 4 MW.nm9 (MarronWand), 1 normix, 3, 4, 5, 6, 9 plot.normix, 3, 5, 5 pnorm, 7 pnormix, 5, 6 print.normix (normix), 4 qnormix (pnormix), 6 r.normix, 8 rnorm, 9 rnormix, 3, 5, 9 uniroot, 7 var.normix (normix), 4 lines, 6 lines.normix (plot.normix), 5 m.normix (normix), 4 MarronWand, 1, 5 mean.normix (normix), 4 MW.nm1 (MarronWand), 1 MW.nm10 (MarronWand), 1 MW.nm11 (MarronWand), 1 MW.nm12 (MarronWand), 1 MW.nm13 (MarronWand), 1 MW.nm14 (MarronWand), 1 MW.nm15 (MarronWand), 1 MW.nm16 (MarronWand), 1 MW.nm2 (MarronWand), 1 MW.nm3 (MarronWand), 1 MW.nm4 (MarronWand), 1 MW.nm5 (MarronWand), 1 MW.nm6 (MarronWand), 1 MW.nm7 (MarronWand), 1 MW.nm8 (MarronWand), 1 11