Re: [R] Creating a specific skewed distribution
Your question is somewhat vague, there are probably an infinite number of distributions that fit your description. Here are 2 possibilities: tmp - sample( c(1,30,60), 1000, replace=TRUE, + prob=c(0.10344, 0.9-0.10344, 0.1)) mean(tmp) [1] 30.00041 mean(tmp=60) [1] 0.1001004 tmp2 - rgamma(1000, shape=1.777666, scale=30/1.777666) mean(tmp2) [1] 29.99674 mean(tmp2=60) [1] 0.003 -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of David Arnold Sent: Tuesday, June 09, 2009 11:49 PM To: r-help@r-project.org Subject: [R] Creating a specific skewed distribution All, Can someone help me create a skewed distribution, mean = 30, with probability of selecting a random number from the distribution greater than or equal 60 equal to 10%? I need the probability density function to equal zero at zero, and have a maximum height at or near 30. Is this possible? And if it is possible, how can I adjust the distribution so that the probability of selecting a random number greater than or equal to 60 is p. Thanks. No idea how to start. David [[alternative HTML version deleted]] __ R-help@r-project.org 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. __ R-help@r-project.org 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.
Re: [R] Creating a specific skewed distribution
With skewed unimodal distributions, the mode can't equal the mean, so assuming you want the mean to be around 30, I find that a weibull function can get close to what you want: mean(rweibull(1e5,1.5,33)) [1] 29.77781 pweibull(60,1.5,33) [1] 0.9138475 I'm sure you can play with the parameters to try to get even closer to what you want. On Wed, Jun 10, 2009 at 2:48 AM, David Arnolddwarnol...@suddenlink.net wrote: All, Can someone help me create a skewed distribution, mean = 30, with probability of selecting a random number from the distribution greater than or equal 60 equal to 10%? I need the probability density function to equal zero at zero, and have a maximum height at or near 30. Is this possible? And if it is possible, how can I adjust the distribution so that the probability of selecting a random number greater than or equal to 60 is p. Thanks. No idea how to start. David [[alternative HTML version deleted]] __ R-help@r-project.org 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 Looking to arrange a meeting? Check my public calendar: http://tr.im/mikes_public_calendar ~ Certainty is folly... I think. ~ __ R-help@r-project.org 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.
Re: [R] Creating a specific skewed distribution
You could also make some algebra. e.g. : ?rweibull gives the formula of the mean and of the cumulative distribution function in the Details section. So using your known parameters (i.e. mean=30 and p(10)=.10, i.e. cumulative function(10) =.90), I think it is sufficient to determine the exact values you want shape and scale to be. And you can do that with any probability function (some easier the calculate) as most (if not all) have these equations. Of course, it might be more pleasing to play with the parameters. Etienne Mike Lawrence wrote: With skewed unimodal distributions, the mode can't equal the mean, so assuming you want the mean to be around 30, I find that a weibull function can get close to what you want: mean(rweibull(1e5,1.5,33)) [1] 29.77781 pweibull(60,1.5,33) [1] 0.9138475 I'm sure you can play with the parameters to try to get even closer to what you want. On Wed, Jun 10, 2009 at 2:48 AM, David Arnolddwarnol...@suddenlink.net wrote: All, Can someone help me create a skewed distribution, mean = 30, with probability of selecting a random number from the distribution greater than or equal 60 equal to 10%? I need the probability density function to equal zero at zero, and have a maximum height at or near 30. Is this possible? And if it is possible, how can I adjust the distribution so that the probability of selecting a random number greater than or equal to 60 is p. Thanks. No idea how to start. David [[alternative HTML version deleted]] __ R-help@r-project.org 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 Looking to arrange a meeting? Check my public calendar: http://tr.im/mikes_public_calendar ~ Certainty is folly... I think. ~ __ R-help@r-project.org 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. -- View this message in context: http://www.nabble.com/Creating-a-specific-skewed-distribution-tp23956114p23963140.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org 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.
Re: [R] Creating a specific skewed distribution
Etienne et al, This is exactly what I need. So I gave it an algebraic try and set: Mean=30=b*gamma(1+1/a), solve for b and substitute into F(60)=0.10. After a little algebra, this left me with [ 2*gamma(1+1/a) ]^a = -ln(0.10) Now, I don't think this has a closed form solution, at least not one I have the skill to find. So, how would I solve this using R? David. On Jun 10, 2009, at 7:09 AM, Etienne B. Racine wrote: You could also make some algebra. e.g. : ?rweibull gives the formula of the mean and of the cumulative distribution function in the Details section. So using your known parameters (i.e. mean=30 and p(10)=.10, i.e. cumulative function(10) =.90), I think it is sufficient to determine the exact values you want shape and scale to be. And you can do that with any probability function (some easier the calculate) as most (if not all) have these equations. Of course, it might be more pleasing to play with the parameters. Etienne Mike Lawrence wrote: With skewed unimodal distributions, the mode can't equal the mean, so assuming you want the mean to be around 30, I find that a weibull function can get close to what you want: mean(rweibull(1e5,1.5,33)) [1] 29.77781 pweibull(60,1.5,33) [1] 0.9138475 I'm sure you can play with the parameters to try to get even closer to what you want. On Wed, Jun 10, 2009 at 2:48 AM, David Arnolddwarnol...@suddenlink.net wrote: All, Can someone help me create a skewed distribution, mean = 30, with probability of selecting a random number from the distribution greater than or equal 60 equal to 10%? I need the probability density function to equal zero at zero, and have a maximum height at or near 30. Is this possible? And if it is possible, how can I adjust the distribution so that the probability of selecting a random number greater than or equal to 60 is p. Thanks. No idea how to start. David [[alternative HTML version deleted]] __ R-help@r-project.org 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 Looking to arrange a meeting? Check my public calendar: http://tr.im/mikes_public_calendar ~ Certainty is folly... I think. ~ __ R-help@r-project.org 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. -- View this message in context: http://www.nabble.com/Creating-a-specific-skewed-distribution-tp23956114p23963140.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org 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. __ R-help@r-project.org 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.
Re: [R] Creating a specific skewed distribution
Here is one way to solve the equation: require(BB) f - function(x) (2*gamma(1+1/x))^x + log (0.10) ans - dfsane(par=1, fn=f) ans Ravi. --- Ravi Varadhan, Ph.D. Assistant Professor, The Center on Aging and Health Division of Geriatric Medicine and Gerontology Johns Hopkins University Ph: (410) 502-2619 Fax: (410) 614-9625 Email: rvarad...@jhmi.edu Webpage: http://www.jhsph.edu/agingandhealth/People/Faculty_personal_pages/Varadhan.h tml -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of David Arnold Sent: Wednesday, June 10, 2009 11:25 AM To: Etienne B. Racine Cc: r-help@r-project.org Subject: Re: [R] Creating a specific skewed distribution Etienne et al, This is exactly what I need. So I gave it an algebraic try and set: Mean=30=b*gamma(1+1/a), solve for b and substitute into F(60)=0.10. After a little algebra, this left me with [ 2*gamma(1+1/a) ]^a = -ln(0.10) Now, I don't think this has a closed form solution, at least not one I have the skill to find. So, how would I solve this using R? David. On Jun 10, 2009, at 7:09 AM, Etienne B. Racine wrote: You could also make some algebra. e.g. : ?rweibull gives the formula of the mean and of the cumulative distribution function in the Details section. So using your known parameters (i.e. mean=30 and p(10)=.10, i.e. cumulative function(10) =.90), I think it is sufficient to determine the exact values you want shape and scale to be. And you can do that with any probability function (some easier the calculate) as most (if not all) have these equations. Of course, it might be more pleasing to play with the parameters. Etienne Mike Lawrence wrote: With skewed unimodal distributions, the mode can't equal the mean, so assuming you want the mean to be around 30, I find that a weibull function can get close to what you want: mean(rweibull(1e5,1.5,33)) [1] 29.77781 pweibull(60,1.5,33) [1] 0.9138475 I'm sure you can play with the parameters to try to get even closer to what you want. On Wed, Jun 10, 2009 at 2:48 AM, David Arnolddwarnol...@suddenlink.net wrote: All, Can someone help me create a skewed distribution, mean = 30, with probability of selecting a random number from the distribution greater than or equal 60 equal to 10%? I need the probability density function to equal zero at zero, and have a maximum height at or near 30. Is this possible? And if it is possible, how can I adjust the distribution so that the probability of selecting a random number greater than or equal to 60 is p. Thanks. No idea how to start. David [[alternative HTML version deleted]] __ R-help@r-project.org 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 Looking to arrange a meeting? Check my public calendar: http://tr.im/mikes_public_calendar ~ Certainty is folly... I think. ~ __ R-help@r-project.org 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. -- View this message in context: http://www.nabble.com/Creating-a-specific-skewed-distribution-tp239561 14p23963140.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org 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. __ R-help@r-project.org 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. __ R-help@r-project.org 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.
Re: [R] Creating a specific skewed distribution
There are actually two roots to your equation: 0.329 and 1.385. f - function(x) (2*gamma(1+1/x))^x + log (0.10) x - seq(0.1, 5, length=500) plot(x, fn(x), type=l) abline(h = 0, lty=2, col=2) Ravi. --- Ravi Varadhan, Ph.D. Assistant Professor, The Center on Aging and Health Division of Geriatric Medicine and Gerontology Johns Hopkins University Ph: (410) 502-2619 Fax: (410) 614-9625 Email: rvarad...@jhmi.edu Webpage: http://www.jhsph.edu/agingandhealth/People/Faculty_personal_pages/Varadhan.h tml -Original Message- From: Ravi Varadhan [mailto:rvarad...@jhmi.edu] Sent: Wednesday, June 10, 2009 11:53 AM To: 'David Arnold'; 'Etienne B. Racine' Cc: 'r-help@r-project.org' Subject: RE: [R] Creating a specific skewed distribution Here is one way to solve the equation: require(BB) f - function(x) (2*gamma(1+1/x))^x + log (0.10) ans - dfsane(par=1, fn=f) ans Ravi. --- Ravi Varadhan, Ph.D. Assistant Professor, The Center on Aging and Health Division of Geriatric Medicine and Gerontology Johns Hopkins University Ph: (410) 502-2619 Fax: (410) 614-9625 Email: rvarad...@jhmi.edu Webpage: http://www.jhsph.edu/agingandhealth/People/Faculty_personal_pages/Varadhan.h tml -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of David Arnold Sent: Wednesday, June 10, 2009 11:25 AM To: Etienne B. Racine Cc: r-help@r-project.org Subject: Re: [R] Creating a specific skewed distribution Etienne et al, This is exactly what I need. So I gave it an algebraic try and set: Mean=30=b*gamma(1+1/a), solve for b and substitute into F(60)=0.10. After a little algebra, this left me with [ 2*gamma(1+1/a) ]^a = -ln(0.10) Now, I don't think this has a closed form solution, at least not one I have the skill to find. So, how would I solve this using R? David. On Jun 10, 2009, at 7:09 AM, Etienne B. Racine wrote: You could also make some algebra. e.g. : ?rweibull gives the formula of the mean and of the cumulative distribution function in the Details section. So using your known parameters (i.e. mean=30 and p(10)=.10, i.e. cumulative function(10) =.90), I think it is sufficient to determine the exact values you want shape and scale to be. And you can do that with any probability function (some easier the calculate) as most (if not all) have these equations. Of course, it might be more pleasing to play with the parameters. Etienne Mike Lawrence wrote: With skewed unimodal distributions, the mode can't equal the mean, so assuming you want the mean to be around 30, I find that a weibull function can get close to what you want: mean(rweibull(1e5,1.5,33)) [1] 29.77781 pweibull(60,1.5,33) [1] 0.9138475 I'm sure you can play with the parameters to try to get even closer to what you want. On Wed, Jun 10, 2009 at 2:48 AM, David Arnolddwarnol...@suddenlink.net wrote: All, Can someone help me create a skewed distribution, mean = 30, with probability of selecting a random number from the distribution greater than or equal 60 equal to 10%? I need the probability density function to equal zero at zero, and have a maximum height at or near 30. Is this possible? And if it is possible, how can I adjust the distribution so that the probability of selecting a random number greater than or equal to 60 is p. Thanks. No idea how to start. David [[alternative HTML version deleted]] __ R-help@r-project.org 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 Looking to arrange a meeting? Check my public calendar: http://tr.im/mikes_public_calendar ~ Certainty is folly... I think. ~ __ R-help@r-project.org 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. -- View this message in context: http://www.nabble.com/Creating-a-specific-skewed-distribution-tp239561 14p23963140.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting
[R] Creating a specific skewed distribution
All, Can someone help me create a skewed distribution, mean = 30, with probability of selecting a random number from the distribution greater than or equal 60 equal to 10%? I need the probability density function to equal zero at zero, and have a maximum height at or near 30. Is this possible? And if it is possible, how can I adjust the distribution so that the probability of selecting a random number greater than or equal to 60 is p. Thanks. No idea how to start. David [[alternative HTML version deleted]] __ R-help@r-project.org 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.