Eleni Rapsomaniki
2006-Aug-07 10:35 UTC
[R] Finding points with equal probability between normal distributions
Dear mailing list, For two normal distributions, e.g: r1 =rnorm(20,5.2,2.1) r2 =rnorm(20,4.2,1.1) plot(density(r2), col="blue") lines(density(r1), col="red") Is there a way in R to compute/estimate the point(s) x where the density of the two distributions cross (ie where x has equal probability of belonging to either of the two distributions)? Many Thanks Eleni Rapsomaniki PhD student Birkbeck College, UK
Uwe Ligges
2006-Aug-07 11:01 UTC
[R] Finding points with equal probability between normal distributions
Eleni Rapsomaniki wrote:> Dear mailing list, > > For two normal distributions, e.g: > > r1 =rnorm(20,5.2,2.1) > r2 =rnorm(20,4.2,1.1) > plot(density(r2), col="blue") > lines(density(r1), col="red")dr1 <- density(r1, from=-3, to=14) dr2 <- density(r2, from=-3, to=14) w <- which(diff(sign(dr2$y - dr1$y)) != 0) dr1$x[w] plot(dr1, ylim = c(0, 0.33)) lines(dr2, col = "red") abline(v = dr1$x[w], col = "blue") Uwe Ligges> Is there a way in R to compute/estimate the point(s) x where the density of the > two distributions cross (ie where x has equal probability of belonging to > either of the two distributions)? > > Many Thanks > > Eleni Rapsomaniki > PhD student > Birkbeck College, UK > > ______________________________________________ > 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.
Dimitris Rizopoulos
2006-Aug-07 11:18 UTC
[R] Finding points with equal probability between normaldistributions
if you want to base it on Normality, then you can use: prob <- function(x){ dnorm((x - 5.2) / 2.1) / 2.1 - dnorm((x - 4.2) / 1.1) / 1.1 } uniroot(prob, c(-3, 3)) otherwise if you want to estimate it you can use Uwe's solution. I hope it helps. Best, Dimitris ---- Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://med.kuleuven.be/biostat/ http://www.student.kuleuven.be/~m0390867/dimitris.htm ----- Original Message ----- From: "Eleni Rapsomaniki" <e.rapsomaniki at mail.cryst.bbk.ac.uk> To: <r-help at stat.math.ethz.ch> Sent: Monday, August 07, 2006 12:35 PM Subject: [R] Finding points with equal probability between normaldistributions> Dear mailing list, > > For two normal distributions, e.g: > > r1 =rnorm(20,5.2,2.1) > r2 =rnorm(20,4.2,1.1) > plot(density(r2), col="blue") > lines(density(r1), col="red") > > Is there a way in R to compute/estimate the point(s) x where the > density of the > two distributions cross (ie where x has equal probability of > belonging to > either of the two distributions)? > > Many Thanks > > Eleni Rapsomaniki > PhD student > Birkbeck College, UK > > ______________________________________________ > 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. >Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
Chris Evans
2006-Aug-07 12:00 UTC
[R] Finding points with equal probability between normal distributions
Eleni Rapsomaniki sent the following at 07/08/2006 11:35:> Dear mailing list, > > For two normal distributions, e.g: > > r1 =rnorm(20,5.2,2.1) > r2 =rnorm(20,4.2,1.1) > plot(density(r2), col="blue") > lines(density(r1), col="red") > > Is there a way in R to compute/estimate the point(s) x where the density of the > two distributions cross (ie where x has equal probability of belonging to > either of the two distributions)?I worry about showing my statistical incompetence or incomprehension but isn't what you need Jacobson et al.'s criterion C for clinical change? I.e. the point at which the misclassification rates in two Normal distributions, one with a higher mean than the other, match. It's at (sd1*mean2 + sd2*mean1)/(sd1 + sd2) So for Eleni's example I think that comes out at 4.544 and if I use:> r1b <- rnorm(200,5.2,2.1) > r2b <- rnorm(200,4.2,1.1) > plot(density(r2b), col="blue") > plot(density(r1b), col="red") > plot(density(r2b), col="blue") > lines(density(r1b), col="red") > cscc <- 4.544 > abline(v=cscc)It happened to work out beautifully:> sum(r1b > cscc)[1] 126> sum(r2b < cscc)[1] 126 of course, set a different seed (I broke the posting rules and didn't set one, yes, I know) you won't get such a nice result every time and with n=20 in each group you'll get much more wobble. Or am I missing something. The original paper, which got reliable change wrong, was: Jacobson, N. S., Follette, W. C. & Revenstorf, D. (1984) Psychotherapy outcome research: methods for reporting variability and evaluating clinical significance. Behavior Therapy, 15, 336-352. There's a summary most people cite at: Jacobson, N. S. & Truax, P. (1991) Clinical significance: a statistical approach to defining meaningful change in psychotherapy research. Journal of Consulting and Clinical Psychology, 59, 12-19. and shameless self-promotion here, I tried to summarise it: Evans, C., Margison, F. & Barkham, M. (1998) The contribution of reliable and clinically significant change methods to evidence-based mental health. Evidence Based Mental Health, 1, 70-72. I hadn't twigged that what the criterion gives is balanced missclassification when I wrote that. I've played with some simulations and it's not as vulnerable to non-Gaussian distributions as I'd expected but someone can probably point to published work, simulation or analytic, on that. Cheers all, Chris