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
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Sun 16 Dec 2007 - 14:26:29 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 17 Dec 2007 - 02:30:19 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.