[R] using optimize with two unknowns, e.g. to parameterize a distribution with given confidence interval

2010-10-15 Thread David LeBauer
Hi,

I would like to write a function that finds parameters of a log-normal
distribution with a 1-alpha CI of (x_lcl, x_ucl):

However, I don't know how to optimize for the two unknown parameters.

Here is my unsuccessful attempt to find a lognormal distribution with
a 90%CI of 1,20:

prior - function(x_lcl, x_ucl, alpha, mean, var) {
  a - (plnorm(x_lcl, mean, var) - (alpha/2))^2
  b - (plnorm(x_ucl, mean, var) - (1-alpha/2))^2
  return(a+b)
  }

optimize(fn=prior, interval = c(-5, 100), 1, 20)

I understand that this problem has a closed form solution, but I would
like to make this a general function.

Thanks,

David

-- 
David LeBauer, PhD
Energy Biosciences Institute
University of Illinois Urbana-Champaign
1206 W. Gregory Drive
Urbana, IL  61801, U.S.A.

__
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] can I add line breaks to the paste() function?

2010-10-01 Thread David LeBauer
Thanks for the help. This solves my problem - I wanted to print out
errors and warnings on separate lines with a single call.

Thanks,

David

On Thu, Sep 30, 2010 at 3:42 PM, Jeremy Miles jeremy.mi...@gmail.com wrote:
 Try using cat instead.  Then \n is the new line character.

 E.g.
  cat(1st line\n2nd line\n)

 Jeremy




 On 30 September 2010 13:30, David LeBauer dleba...@gmail.com wrote:
 Can I add a line break to the paste() function to return the following:

 'this is the first line'
 'this is the second line'

 instead of
 'this is the first line this is the second line'

 ?

 __
 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.




 --
 Jeremy Miles
 Psychology Research Methods Wiki: www.researchmethodsinpsychology.com




-- 
David LeBauer, PhD
Energy Biosciences Institute
University of Illinois Urbana-Champaign
1206 W. Gregory Drive
Urbana, IL  61801, U.S.A.

__
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] can I add line breaks to the paste() function?

2010-09-30 Thread David LeBauer
Can I add a line break to the paste() function to return the following:

'this is the first line'
'this is the second line'

instead of
'this is the first line this is the second line'

?

__
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] is there a function to find the quantile of the mean of a vector?

2010-06-18 Thread David LeBauer
Jorge,

Thanks for your help. which.min() on the sorted vector divided by the
vector length gave me the value I was looking for (I was looking for
the probability p(mean(x) | x)):

 x - runif(1000)
 x.sort - sort(x)
 x.length - length(x)
 x.mean - mean(x)
 p.mean - which.min((x.sort - x.mean)^2) / x.length

Another user pointed out a function suited for this purpose, findInterval()

 p.mean - findInterval(x.mean, xsort) / x.length

Thanks for your help,

David

On Thu, Jun 17, 2010 at 10:15 PM, Jorge Ivan Velez
jorgeivanve...@gmail.com wrote:
 Hi David,
 You might try:
 set.seed(1)
 x - runif(10, 3, 7)
 x
  [1] 4.062035 4.488496 5.291413 6.632831 3.806728 6.593559 6.778701 5.643191
 5.516456 3.247145
 (x-mean(x))^2
  [1] 1.308783661 0.514892188 0.007285983 2.035688832 1.958118177 1.925165288
 2.473214156
  [8] 0.191087609 0.096348590 3.837329960
 which.min((x-mean(x))^2)
 [1] 3
 x[which.min((x-mean(x))^2)]
 [1] 5.291413
 which.min(scale(x, scale = FALSE)**2)
 [1] 3
 See ?which.min and ?scale for more information.
 HTH,
 Jorge

 On Thu, Jun 17, 2010 at 7:06 PM, David LeBauer  wrote:

 Hello,

 I am interested in finding the quantile of the mean of a vector,
 something analogous to using the pnorm(), but for an mcmc chain
 instead of a distribution with known parameters.

 One approach would be to write a function that finds the index of x_i
 that minimizes (x-mean(x))^2

 I suspect there is a function available to do this, but I can't find it?

 Thank you,

 David

 __
 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.





-- 
David LeBauer, PhD
Energy Biosciences Institute
University of Illinois Urbana-Champaign
1206 W. Gregory Drive
Urbana, IL  61801, U.S.A.

__
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] is there a function to find the quantile of the mean of a vector?

2010-06-17 Thread David LeBauer
Hello,

I am interested in finding the quantile of the mean of a vector,
something analogous to using the pnorm(), but for an mcmc chain
instead of a distribution with known parameters.

One approach would be to write a function that finds the index of x_i
that minimizes (x-mean(x))^2

I suspect there is a function available to do this, but I can't find it?

Thank you,

David

__
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.