# Re: [R] Truncated normal distribution

From: ravirrrr <ravi.longia_at_gmail.com>
Date: Sun, 16 Dec 2007 06:22:13 -0800 (PST)

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.

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help