Displaying 20 results from an estimated 3000 matches similar to: "Creating q and p functions from a self-defined distribut"
2007 Mar 15
1
Creating q and p functions from a self-defined distribution
Hello all,
I am fishing for some suggestions on efficient ways to make qdist and
pdist type functions from an arbitrary distribution whose probability
density function I've defined myself.
For example, let's say I have a distribution whose pdf is:
dRN <- function(x,d,v,s)
# d, v, and s are parameters
return(d/x^2/sv/sqrt(2*pi)*exp(-(d-v*x)^2/2/(sv^2*x^2)))
this is a legitimate
2007 Mar 29
1
ansari.test.default: bug in call to uniroot?
A recent message on ansari.test() prompted me to play with the examples. This
doesn't work for me in R version 2.4.1
R> ansari.test(rnorm(100), rnorm(100, 0, 2), conf.int = TRUE)
Error in uniroot(ab, srange, tol = 1e-04, zq = qnorm(alpha/2, lower = FALSE)) :
object "ab" not found
It looks like there's a small typo in ccia() inside
ansari.test.default() in which
2010 Feb 02
2
Yield to Maturity using R
Dear R helpers,
Yesterday I had raised following query which was addressed by Mr Ellison. The query and the wonderful solution as provided by Mr. Ellison are as given below.
## PROBLEM
I am calculating the 'Yield to Maturity' for the Bond with following characteristics.
Its a $1000 face value, 3 year bond with 10% annual coupon and is priced at 101. The yield to maturity can be
2012 Dec 20
3
Optmatch Package Question
Hello ,
My optmatch package is loaded on R and otherwise running fine.
I get an error after lcds successfully completes a logistic regression and
I then try to obtain a propensity score:
pdist <- pscore.dist(lcds)
Error: could not find function "pscore.dist"
Does anyone know if pscore.dist is part of the optmatch package,
or is it contained in another package that I need to
2013 May 30
2
RFC: a "safe" uniroot() function for future R
With main R releases only happening yearly in spring, now is
good time to consider *and* discuss new features for what we
often call "R-devel" and more officially is
R Under development (unstable) (.....) -- "Unsuffered Consequences"
Here is one such example I hereby expose to public scrutiny:
A few minutes ago, I've committed the following to R-devel
(the
2011 Apr 03
1
How do I modify uniroot function to return .0001 if error ?
I am calling the uniroot function from inside another function using these
lines (last two lines of the function) :
d <- uniroot(k, c(.001, 250), tol=.05)
return(d$root)
The problem is that on occasion there's a problem with the values I'm
passing to uniroot. In those instances uniroot stops and sends a message
that it can't calculate the root because f.upper * f.lower is greater
2020 Oct 06
0
Solving a simple linear equation using uniroot give error object 'x' not found
On 06/10/2020 11:00 a.m., Sorkin, John wrote:
> Colleagues,
> I am trying to learn to use uniroot to solve a simple linear equation. I define the function, prove the function and a call to the function works. When I try to use uniroot to solve the equation I get an error message,
> Error in yfu n(x,10,20) : object 'x' not found.
>
> I hope someone can tell we how I can fix
2018 Aug 13
0
trace in uniroot() ?
I tend to avoid the the trace/verbose arguments for the various root
finders and optimizers and instead use the trace function or otherwise
modify the function handed to the operator. You can print or plot the
arguments or save them. E.g.,
> trace(ff, print=FALSE, quote(cat("x=", deparse(x), "\n", sep="")))
[1] "ff"
> ff0 <- uniroot(ff, c(0, 10))
2011 Aug 22
1
d, p, q, r - What are the math relations with each other of this functions?
Hi all,
Using the exponential distribution to exemplify: The dexp function is
the PDF (1) and pexp is the CDF (2), that is obtained integrating the
PDF. How can I get the qexp and the rexp? Considering that I have the
PDF, how this two are mathematically related to the PDF?
(1) ke^{-kx}
(2) 1-e^{kx}
Thanks in advance.
2012 Dec 18
1
pscore.dist problem when running optmatch
Hello
My optmatch package is loaded and otherwise running fine.
I get an error after lcds successfully completes logistic regression and
I'm trying to obtain a propensity score:
> pdist <- pscore.dist(lcds)
Error: could not find function "pscore.dist"
I searched the help files, other online sources, could find no answer for
this.
Any advice would be greatly appreciated!
2012 Nov 01
1
What does uniroot return when an error occurs
Hi,
I'm using the uniroot function, and would like to detect an error which
occurs, for instance, when the values at endpoints are not of opposite
signs. For example:
uniroot( function(x) x^2+1, lower=1, upper=2 ).
I want to say something like:
if "error in uniroot(...)" return NA else return uniroot$root
Thanks a lot!
Asaf
--
View this message in context:
2011 Jul 30
2
NAN problem
Hi All,
Did anyone else have a problem like this? I am sorry if its a small issue, I
seem to not understand what to do to get rid of this error.
> Sigma
[1] 0.1939025
> MuRest
[1] 8.512772
> TauZero
[1] 0.1
> curve(qlnorm(x,-TauZero+MuRest, Sigma,lower.tail=F), xlim=c(4000,9000),
ylim=c(0,.99),xlab="", ylab="")
Warning message:
In qlnorm(p, meanlog, sdlog,
1999 Apr 23
1
[S] uniroot -- doesn't work recursively
Dear Prof Azzalini,
You have an interesting example of recursive use of uniroot().
[re-cited at the end]
However, note that R currently has the same problem as S-plus:
Uniroot() doesn't work reliably, recursively.
When you found it to be better, you were just lucky.
The relevant file in R's source, src/main/optimize.c
says
/* WARNING : As things stand, these routines should
2018 Aug 13
1
trace in uniroot() ?
Despite my years with R, I didn't know about trace(). Thanks.
However, my decades in the minimization and root finding game make me like having
a trace that gives some info on the operation, the argument and the current function value.
I've usually found glitches are a result of things like >= rather than > in tests etc., and
knowing what was done is the quickest way to get there.
2011 Apr 02
1
uniroot speed and vectorization?
curiosity---given that vector operations are so much faster than
scalar operations, would it make sense to make uniroot vectorized? if
I read the uniroot docs correctly, uniroot() calls an external C
routine which seems to be a scalar function. that must be slow. I am
thinking a vectorized version would be useful for an example such as
of <- function(x,a) ( log(x)+x+a )
uniroot( of, c(
2012 Apr 07
1
Uniroot error
Dear All
I am trying to find a uniroot of a function within another function (see
example) but I am getting an error message (f()values at end points not of
opposite sign). I was wondering if you would be able to advise how redefine
my function so that I can find the solution. In short my first function
calculates the intergrale which is function of "t" , I need to find the
uniroot of
2007 Jan 31
2
what is the purpose of an error message in uniroot?
Hi all,
This is probably a blindingly obvious question: Why does it matter in
the uniroot function whether the f() values at the end points that you
supply are of the same sign?
For example:
f <- function(x,y) {y-x^2+1}
#this gives a warning
uniroot(f,interval=c(-5,5),y=0)
Error in uniroot(f, interval=c(-5, 5), y = 0) : f() values at end
points not of opposite sign
#this doesn't give a
2023 Feb 18
1
uniroot violates bounds?
I wrote first cut at unirootR for Martin M and he revised and put in
Rmpfr.
The following extends Ben's example, but adds the unirootR with trace
output.
c1 <- 4469.822
c2 <- 572.3413
f <- function(x) { c1/x - c2/(1-x) }; uniroot(f, c(1e-6, 1))
uniroot(f, c(1e-6, 1))
library(Rmpfr)
unirootR(f, c(1e-6, 1), extendInt="no", trace=1)
This gives more detail on the iterations,
2011 May 06
1
Uniroot - error
Hi,
I have tried to use uniroot to solve a value (value a in my function) that
gives f=0, and I repeat this process for 10000 times(stimulations). However
error occures from the 4625th stimulation - Error in uniroot(f, c(0, 2),
maxiter = 1000, tol = 0.001) :
f() values at end points not of opposite sign
I have also tried interval of (lower=min(U), upper=max(U)) and it won't work
as well.
2007 Dec 06
1
Integral implicit function
Hi,
Could somebody help me with the following. I want to calculate the integral over an implicit function. I thought to integrate over a function depending on uniroot. In previous topics I found a thread about finding the root of an integral. And that works. But the other way around, does not work. Does R support this?
I included the following example. The function in the example is very easy