Xavier Prudent
2013-Nov-05 14:36 UTC
[R] Regression of the sum of distributions on an histogram with R
Dear all, I hope that is the right list for my question Here is the case: I want to describe an histogram as the sum of several distributions, and thus to fit these distributions on that histogram. In ROOT/C++ that is pretty obvious, but I look for the equivalent in R. Here is a self-explanatory exemple: ## SUM OF TWO GAUSSIANS OF DIFFERENT WIDTHS x=rnorm(n=1000,mean=0,sd=1) y=rnorm(n=1000,mean=0,sd=3) z=append(x,y) b=seq(-10,10,by=0.25) hist(z,breaks=b) In this case the individual contributions (x) and (y) are known, and I can extract their density curves with a Kernel: ## NARROW GAUSSIAN hist(x,prob=T,breaks=b) dx=density(x,ker="epan") lines(dx,col=3,lwd=2) ## WIDE GAUSSIAN hist(y,prob=T,breaks=b) dy=density(y,ker="epan") lines(dy,col=2,lwd=2) I would like to do something like z~dx+dy Where the fractions of dx and dy would be the parameters to be fitted. Looking into the R documentation I have only found references to single regression and smoothing. Does anyone have a clue or a sympathetic link? I found various tools, but either they assume Gaussian distributions, or, as mixtools, they don't accept user-defined functions. Thanks in advance, X. -- *---------------------------------------Xavier Prudent* *Computational biology and evolutionary genomics* *Guest scientist at the Max-Planck-Institut für Physik komplexer Systeme* *(MPI-PKS)* *Noethnitzer Str. 38* *01187 Dresden * *Max Planck-Institute for Molecular Cell Biology and Genetics* *(MPI-CBG)* *Pfotenhauerstraße 108 * *01307 Dresden* *Phone: +49 351 210-2621* *Mail: prudent [ at ] mpi-cbg.de <http://mpi-cbg.de>* *---------------------------------------* [[alternative HTML version deleted]]