Is there an R function / package that can perform inverse normal distribution? [duplicate] - r

To plot a normal distribution curve in R we can use:
(x = seq(-4,4, length=100))
y = dnorm(x)
plot(x, y)
If dnorm calculates y as a function of x, does R have a function that calculates x as a function of y? If not what is the best way to approach this?

What dnorm() is doing is giving you a probability density function. If you integrate over that, you would have a cumulative distribution function (which is given by pnorm() in R). The inverse of the CDF is given by qnorm(); that is the standard way these things are conceptualized in statistics.

I'm not sure if the inverse of the density function is built in -- it's not used nearly as often as the inverse of the cumulative distribution function. I can't think offhand of too many situation where the inverse density function is useful. Of course, that doesn't mean there aren't any, so if you are sure this is the function you need, you could just do:
dnorminv<-function(y) sqrt(-2*log(sqrt(2*pi)*y))
plot(x, y)
points(dnorminv(y),y,pch=3)

The derivation of the inverse of the standard normal pdf is:

Related

How to get analytical formula of probability density function and cumulative distribution function for a distribution in R?

Is there anyway to print out the PDF/CDF formula for a distribution? E.g. for normal distribution I wish to run a command and see some formula printed f(x) = 1/sqrt(.....)...
I want to translate R's implementation of distributions like hyperbolic and EGB2 into Python and hope there is a way to fetch the formula from R elegantly rather than looking into the source code.

How do I use the pgamma() function in R to compute the CDF of a gamma distribution?

I want to compute the cumulative distribution function in R for data that follows a gamma distribution. I understood how to do this with a lognormal distribution using the equation from Wikipedia; however, the gamma equation seems more complicated and I decided to use the pgamma() function.
I'm new to this and don't understand the following:
Why do I get three different values out of pgamma, and how does it make sense that they are negative?
Am I supposed to take the log of all the quantiles, just as I used log(mean) and log(standard deviation) when doing calculations with a lognorm distribution?
How do I conceptually understand the CDF calculated by pgamma? It made sense for lognorm that I was calculating the probability that X would take a value <= x, but there is no "x" in this pgamma function.
Really appreciate the help in understanding this.
shape <- 1.35721347
scale <- 1/0.01395087
quantiles <- c(3.376354, 3.929347, 4.462594)
pgamma(quantiles, shape = shape, scale = scale, log.p = TRUE)

Prediction at a new value using lowess function in R

I am using lowess function to fit a regression between two variables x and y. Now I want to know the fitted value at a new value of x. For example, how do I find the fitted value at x=2.5 in the following example. I know loess can do that, but I want to reproduce someone's plot and he used lowess.
set.seed(1)
x <- 1:10
y <- x + rnorm(x)
fit <- lowess(x, y)
plot(x, y)
lines(fit)
Local regression (lowess) is a non-parametric statistical method, it's a not like linear regression where you can use the model directly to estimate new values.
You'll need to take the values from the function (that's why it only returns a list to you), and choose your own interpolation scheme. Use the scheme to predict your new points.
Common technique is spline interpolation (but there're others):
https://www.r-bloggers.com/interpolation-and-smoothing-functions-in-base-r/
EDIT: I'm pretty sure the predict function does the interpolation for you. I also can't find any information about what exactly predict uses, so I've tried to trace the source code.
https://github.com/wch/r-source/blob/af7f52f70101960861e5d995d3a4bec010bc89e6/src/library/stats/R/loess.R
else { ## interpolate
## need to eliminate points outside original range - not in pred_
I'm sure the R code calls the underlying C implementation, but it's not well documented so I don't know what algorithm it uses.
My suggestion is: either trust the predict function or roll out your own interpolation algorithm.

how to specify objective function in nls() function in R

I have created an objective function f(x0) that returns sum of squares between actual and theoretical values by specifying intial guess x0. How do I specify minimization problem using nls() function?
Thanks in advance.

What is the equivalent R function to GAMMA.INV(probability,alpha,beta) Excel function?

I need to find the inverse of the gamma cumulative distribution. I know there is GAMMA.INV(probability,alpha,beta) function just to do that in excel. How can I achieve this in R language?
In R, for most probability distributions,
there are four functions, called d, p, q, r,
(e.g., dnorm, pnorm, qnorm, rnorm)
giving you the density (d), cumulative distribution function (p, since the result is a probability), its inverse (q, since the result is a quantile), and r to sample from the distribution.
For the Gamma distribution, the inverse of the cumulative distribution function is therefore qgamma.

Resources