Hello,
Thanks very much for your kind response. Yes, if I multiply by the width
"35", the area should be equal to one.
How can I plot the probability bars rather than density bars? That is, I
would like the height of the first bar to be 0.279, which is the
probability that the variable falls between 0 and 35.
Thanks,
miao
2012/3/12 Rolf Turner
>
> Why do you say that the area is much lower than 1?
> It is exactly equal to 1.
>
> How did you calculate this area?
>
> Your code seems extremely convoluted and confused.
>
> You could construct your (rather bizarre) vector Y1 much
> more simply as
>
> Y1 <- rep((0.5 + 0:9)*35,c(277,146,99,80,69,63,**52,53,55,98))
>
> What do you think you are accomplishing via that call to par()
> given *after* the plotting has been done?
>
> Why set ylim to a value that is so incommensurate with the
> heights of the histogram bars?
>
> cheers,
>
> Rolf Turner
>
>
> On 12/03/12 20:42, jpm miao wrote:
>
>> Hello,
>>
>> I have problem running the histogram function "hist". The area under
>> the
>> histogram is much lower than 1. Could anyone tell me what the problem is?
>> Thanks,
>> (The total number of observation is 992 (close to 1000), so the
>> probability that 0>
> Why are you approximating? The empirical probability is exactly
> equal to 277/992 = 0.2792339.
>
> miao
>>
>>
>>
>> rm(list=ls())
>> par(mfrow=c(1, 1))
>> Y<- cbind(matrix(35*0.5,1,277), matrix(35*1.5, 1, 146), matrix(35*2.5, 1,
>> 99), matrix(35*3.5,1,80), matrix(35*4.5, 1, 69), matrix(35*5.5, 1, 63),
>> matrix(35*6.5, 1, 52), matrix(35*7.5,1, 53), matrix(35*8.5, 1, 55),
>> matrix(35*9.5, 1, 98))
>> Y1<-as.vector(Y)
>> par(mar=c(4.5, 4.1, 3.1, 0))
>> hist(Y1, breaks=seq(0, 350, by=35), ylim=c(0, 0.3), col="grey80",
>> freq=FALSE)
>> par(mar=c(5.1, 4.1, 4.1, 2.1))
>>
>
[[alternative HTML version deleted]]