[R-sig-teaching] Example(s) of Biomodal distributions
chubukou at patfiza.net
chubukou at patfiza.net
Mon Jan 16 15:10:14 CET 2012
I think AbouEl-Makarim means "bimodal distribution" here is my solve
(sorry for primitive example)
m1<-0;
sd1<-1;
m2<-4;
sd2<-1;
bimodal<-curve(dnorm(x,m1,sd1)+dnorm(x,m2,sd2),
from=min(c(m1,m2))-3*max(c(sd1,sd2)),
to=max(c(m1,m2))+3*max(c(sd1,sd2)));
ql_1<-quantile(rnorm(1000,m1,sd1),0.05);
qh_1<-quantile(rnorm(1000,m1,sd1),0.95);
ql_2<-quantile(rnorm(1000,m2,sd2),0.05);
qh_2<-quantile(rnorm(1000,m2,sd2),0.95);
plot(bimodal$x, bimodal$y, type="l");
abline(v=ql_1, col="red",lwd=2);
abline(v=qh_1, col="red",lwd=2);
abline(v=ql_2, col="green", lwd=2);
abline(v=qh_2, col="green", lwd=2);
polygon(x=c(ql_1,qh_1, bimodal$x[bimodal$x<=qh_1 && bimodal$x>=ql_1]),
y=c(0,0,bimodal$y[bimodal$x<=qh_1 && bimodal$x>=ql_1]), col="gray");
polygon(x=c(ql_2,qh_2, bimodal$x[bimodal$x<=qh_2 && bimodal$x>=ql_2]),
y=c(0,0,bimodal$y[bimodal$x<=qh_2 && bimodal$x>=ql_2]), col="gray");
--
Zhan Chubukou
Chair of Pathological Physiology magistrant
Gomel State Medical University
Belarus
> Just noticing that I read the post below too quickly and thought it
> said "binomial" rather than "bimodal". But my solution works all the
> same, you just need to provide a bimodal distribution as the first
> argument. The only requirement is that if the name of your
> distribution is "foo", then dfoo, pfoo, and qfoo need to exist and do
> the correct things. They may be user defined functions.
>
> You can of course, use the groups argument however you like to define
> the tails of the distribution. For example, something like
>
> groups = ( x < qfoo(0.05, ....) | x > qfoo(0.95) )
>
> should shade the tails differently from the center.
>
> In view of the email from Jeff Laux, I might consider adding some
> utilities to build new dfoo, pfoo, and qfoo functions from existing
> ones, at least for a few easy cases, like linear combinations. That
> would make it really easy to generate various bimodal distributions.
>
> ---rjp
>
>
>
>
> On Jan 15, 2012, at 2:41 PM, AbouEl-Makarim Aboueissa wrote:
>
>> Dear R users:
>>
>> I am currently teaching a course in Statistics. Can someone give an
>> R code(s) to create a biomodal curve(s) with shaded area of 90% and
>> with 5% in each tail
>>
>> With many thanks
>> abou
>>
>>
>>
>> ==========================
>> AbouEl-Makarim Aboueissa, Ph.D.
>> Associate Professor of Statistics
>> Graduate Program Coordinator
>> Department of Mathematics & Statistics
>> University of Southern Maine
>> 96 Falmouth Street
>> P.O. Box 9300
>> Portland, ME 04104-9300
>> USA
>>
>>
>> Tel: (207) 228-8389
>> Fax: (207) 780-5607
>> Email: aaboueissa at usm.maine.edu
>> aboueiss at yahoo.com
>>
>> Office: 301C Payson Smith
>>
>>
>> [[alternative HTML version deleted]]
>>
>> _______________________________________________
>> R-sig-teaching at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-sig-teaching
>
> _______________________________________________
> R-sig-teaching at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-teaching
More information about the R-sig-teaching
mailing list