Re: [R] polygon error?

From: Mike Lawrence <Mike.Lawrence_at_dal.ca>
Date: Sat, 26 May 2007 08:06:14 -0300

polygon expects to be given the vertices, so if you want the area under the curve you'll want to include vertices at density=0

z <- pretty(c(-3,3), 100)
ht <- dnorm(z)
plot(z,ht, type="l")

zc <- 1.645
ht<-ht[z>zc]
z<-z[z>zc]

ht<-c(0,ht,0)
z<-c(z[1],z,z[length(z)])

polygon(z,ht,col='red')

On 26-May-07, at 7:34 AM, LL wrote:

> Hi.. I'm not sure why polygon returns an area above the standard
> normal curve.
>
> z <- pretty(c(-3,3), 100)
> ht <- dnorm(z)
> data <- data.frame(z=z, ht=ht)
> zc <- 1.645
> plot(data, type="l")
> lines(data)
> t <- subset(data, z>zc)
> polygon(t, col="red")
>
> Thanks,
> Lance
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help_at_stat.math.ethz.ch mailing list
> 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.

--
Mike Lawrence
Graduate Student, Department of Psychology, Dalhousie University

Website: http://myweb.dal.ca/mc973993
Public calendar: http://icalx.com/public/informavore/Public

"The road to wisdom? Well, it's plain and simple to express:
Err and err and err again, but less and less and less."
	- Piet Hein

______________________________________________
R-help_at_stat.math.ethz.ch mailing list
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.
Received on Sat 26 May 2007 - 11:11:50 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 26 May 2007 - 11:31:30 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.