On 31/01/15 21:10, C W wrote:
Hi Bill,
One quick question. What if I wanted to use curve() for a uniform
distribution?
Say, unif(0.5, 1.3), 0 elsewhere.
My R code:
func <- function(min, max){
1 / (max - min)
}
curve(func(min = 0.5, max = 1.3), from = 0, to = 2)
curve() wants an expression, but I have a constant. And I want zero
everywhere else.
Well if that's what you want, then say so!!!
func <- function(x,min,max) {
ifelse(x < min | x > max, 0, 1/(max - min))
}
curve(func(u,0.5,1.3),0,2,xname="u")
Or, better (?) curve(func(u,0.5,1.3),0,2,xname="u",type="s")
which avoids the slight slope in the "vertical" lines.
cheers,
Rolf Turner
--
Rolf Turner
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276
Home phone: +64-9-480-4619
______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.