FJ M
2012-Jul-24 02:23 UTC
[R] Integrate(dnorm) with different mean and standard deviation help
I'm trying to provide different parameters to the integrate function for various probability functions. I'm using dnorm as the simplest example here. For instance integrate(dnorm, -1.96, 1.96) produces the correct answer for a normal distribution with mean 0 and standard deviation 1. I've tried two ways to use mean=2.0 and standard deviation 1, but with no luck. The examples follow.> integrate(dnorm, -1.96, 1.96)0.9500042 with absolute error < 1e-11> mean = 2.0 > sd = 1.0 > integrate(dnorm, -1.96, 1.96)0.9500042 with absolute error < 1e-11> integrate(dnorm(mean=2.0,sd=1.0), -1.96, 1.96)Error in .Internal(dnorm(x, mean, sd, log)) : 'x' is missing Calls: integrate -> match.fun -> dnorm Execution halted How do I change the built in mean=0 and standard deviation=1 for dnorm using integrate? Thanks, Frank Chicago, IL [[alternative HTML version deleted]]
arun
2012-Jul-24 02:42 UTC
[R] Integrate(dnorm) with different mean and standard deviation help
Hi, Check this link (https://stat.ethz.ch/pipermail/r-help/2010-February/227902.html). Hope it helps. A.K. ----- Original Message ----- From: FJ M <chicagobrownblue at hotmail.com> To: R <r-help at r-project.org> Cc: Sent: Monday, July 23, 2012 10:23 PM Subject: [R] Integrate(dnorm) with different mean and standard deviation help I'm trying to provide different parameters to the integrate function for various probability functions. I'm using dnorm as the simplest example here. For instance integrate(dnorm, -1.96, 1.96) produces the correct answer for a normal distribution with mean 0 and standard deviation 1. I've tried two ways to use mean=2.0 and standard deviation 1, but with no luck. The examples follow.> integrate(dnorm, -1.96, 1.96)0.9500042 with absolute error < 1e-11> mean = 2.0 > sd = 1.0 > integrate(dnorm, -1.96, 1.96)0.9500042 with absolute error < 1e-11> integrate(dnorm(mean=2.0,sd=1.0), -1.96, 1.96)Error in .Internal(dnorm(x, mean, sd, log)) : 'x' is missing Calls: integrate -> match.fun -> dnorm Execution halted How do I change the built in mean=0 and standard deviation=1 for dnorm using integrate? Thanks, Frank Chicago, IL ??? ??? ??? ? ??? ??? ? ??? [[alternative HTML version deleted]] ______________________________________________ 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.
Pascal Oettli
2012-Jul-24 02:48 UTC
[R] Integrate(dnorm) with different mean and standard deviation help
Hello, Maybe the following could help: > f <- function(x) dnorm(x, mean=2, sd=1) > integrate(f, -1.96, 1.96) 0.4840091 with absolute error < 1.4e-12 HTH Regards. Le 24/07/2012 11:23, FJ M a ?crit :> > I'm trying to provide different parameters to the integrate function for various probability functions. I'm using dnorm as the simplest example here. For instance integrate(dnorm, -1.96, 1.96) produces the correct answer for a normal distribution with mean 0 and standard deviation 1. I've tried two ways to use mean=2.0 and standard deviation 1, but with no luck. The examples follow. > > >> integrate(dnorm, -1.96, 1.96) > 0.9500042 with absolute error < 1e-11 >> mean = 2.0 >> sd = 1.0 >> integrate(dnorm, -1.96, 1.96) > 0.9500042 with absolute error < 1e-11 >> integrate(dnorm(mean=2.0,sd=1.0), -1.96, 1.96) > Error in .Internal(dnorm(x, mean, sd, log)) : 'x' is missing > Calls: integrate -> match.fun -> dnorm > Execution halted > > How do I change the built in mean=0 and standard deviation=1 for dnorm using integrate? > > Thanks, > > Frank > Chicago, IL > [[alternative HTML version deleted]] > > ______________________________________________ > 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. >
Jorge I Velez
2012-Jul-24 02:53 UTC
[R] Integrate(dnorm) with different mean and standard deviation help
Try> integrate(dnorm, mean = 2, sd = 1, -1.96, 1.96)0.4840091 with absolute error < 1.4e-12 HTH, Jorge.- On Mon, Jul 23, 2012 at 10:23 PM, FJ M <> wrote:> > I'm trying to provide different parameters to the integrate function for > various probability functions. I'm using dnorm as the simplest example > here. For instance integrate(dnorm, -1.96, 1.96) produces the correct > answer for a normal distribution with mean 0 and standard deviation 1. I've > tried two ways to use mean=2.0 and standard deviation 1, but with no luck. > The examples follow. > > > > integrate(dnorm, -1.96, 1.96) > 0.9500042 with absolute error < 1e-11 > > mean = 2.0 > > sd = 1.0 > > integrate(dnorm, -1.96, 1.96) > 0.9500042 with absolute error < 1e-11 > > integrate(dnorm(mean=2.0,sd=1.0), -1.96, 1.96) > Error in .Internal(dnorm(x, mean, sd, log)) : 'x' is missing > Calls: integrate -> match.fun -> dnorm > Execution halted > > How do I change the built in mean=0 and standard deviation=1 for dnorm > using integrate? > > Thanks, > > Frank > Chicago, IL > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@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. >[[alternative HTML version deleted]]
Rolf Turner
2012-Jul-24 02:55 UTC
[R] Integrate(dnorm) with different mean and standard deviation help
integrate(dnorm, -1.96, 1.96, mean=2, sd=1) Read the help for integrate! It tells you that the integrate function has a "..." argument which consists of "additional arguments to be passed to f". cheers, Rolf Turner On 24/07/12 14:23, FJ M wrote:> I'm trying to provide different parameters to the integrate function for various probability functions. I'm using dnorm as the simplest example here. For instance integrate(dnorm, -1.96, 1.96) produces the correct answer for a normal distribution with mean 0 and standard deviation 1. I've tried two ways to use mean=2.0 and standard deviation 1, but with no luck. The examples follow. > > >> integrate(dnorm, -1.96, 1.96) > 0.9500042 with absolute error < 1e-11 >> mean = 2.0 >> sd = 1.0 >> integrate(dnorm, -1.96, 1.96) > 0.9500042 with absolute error < 1e-11 >> integrate(dnorm(mean=2.0,sd=1.0), -1.96, 1.96) > Error in .Internal(dnorm(x, mean, sd, log)) : 'x' is missing > Calls: integrate -> match.fun -> dnorm > Execution halted > > How do I change the built in mean=0 and standard deviation=1 for dnorm using integrate?