[R] Truncated normal distribution
ravirrrr
ravi.longia at gmail.com
Sun Dec 16 15:22:13 CET 2007
I have the following code, where we need to solve for mu and sigma, when we
have mut and sdt. Can you suggest how to use a solve function in R to do
that? I am new to R and am not sure how to go from defining the functions,
to solving for them.
Thanks
truncated <- function(x)
{
mu=x[1];
sigma=x[2];
f <- function(x) (1/(sigma*sqrt(2*pi)))*exp(-(x-mu)^2/(2*sigma^2));
pdf.fun <- function(x) x*f(x);
sd.fun <- function(x) (x)^2*f(x);
st=integrate(sd.fun,lower=-Inf,upper=1)$value;
a=integrate(pdf.fun,lower=-Inf,upper=1)$value;
a1=integrate(f,lower=-Inf,upper=1)$value;
mut <- a/a1;
sdt <- sqrt((st/a1)-(a/a1)^2);
}
--
View this message in context: http://www.nabble.com/Truncated-normal-distribution-tp14348951p14361967.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list