Nils Hoeller
2007-Jan-21 19:27 UTC
[R] Integration + Normal Distribution + Directory Browsing Processing Questions
Hi everyone, I am new to R, but it's really great and helped me a lot! But now I have 2 questions. It would be great, if someone can help me: 1. I want to integrate a normal distribution, given a median and sd. The integrate function works great BUT the first argument has to be a function so I do integrate(dnorm,0,1) and it works with standard m. and sd. But I have the m and sd given. So for fixed m and sd I work around with a new function mynorm mynorm <- function(n) { ret <- dnorm(n,0.6,0.15) ret } for example. BUT what can I do for dynamic m and sd? I want something like integrate(dnorm(,0.6,0.15),0,1), with the first dnorm parameter open for the integration but fixed m and sd. I hope you can help me. 2. I am working with textfiles with rows of measure data. read.table("file") works fine. Now I want R to read.table all files within a given directory and process them one by the other. for(all files in dir xy) { x <- read.table(nextfile) process x } Is that possible with R? I hope so. Can anyone give me a link to examples. Thanks for your help Nils
Dimitris Rizopoulos
2007-Jan-21 20:37 UTC
[R] Integration + Normal Distribution + Directory Browsing Processing Questions
you can use the `...' argument of integrate, e.g., integrate(dnorm, 0, 1) integrate(dnorm, 0, 1, mean = 0.1) integrate(dnorm, 0, 1, mean = 0.1, sd = 1.2) look at ?integrate for more info. I hope it helps. Best, Dimitris ---- Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://med.kuleuven.be/biostat/ http://www.student.kuleuven.be/~m0390867/dimitris.htm Quoting Nils Hoeller <mail at nhoeller.de>:> Hi everyone, > > I am new to R, but it's really great and helped me a lot! > > But now I have 2 questions. It would be great, if someone can help me: > > 1. I want to integrate a normal distribution, given a median and sd. > The integrate function works great BUT the first argument has to be a > function > > so I do integrate(dnorm,0,1) and it works with standard m. and sd. > > But I have the m and sd given. > > So for fixed m and sd I work around with a new function mynorm > > mynorm <- function(n) { > ret <- dnorm(n,0.6,0.15) > ret > } > > for example. > > BUT what can I do for dynamic m and sd? > I want something like integrate(dnorm(,0.6,0.15),0,1), with the first > dnorm parameter open for the > integration but fixed m and sd. > > I hope you can help me. > > 2. I am working with textfiles with rows of measure data. > read.table("file") works fine. > > Now I want R to read.table all files within a given directory and > process them one by the other. > > for(all files in dir xy) { > x <- read.table(nextfile) > process x > } > > Is that possible with R? I hope so. Can anyone give me a link to examples. > > Thanks for your help > > Nils > > ______________________________________________ > R-help at stat.math.ethz.ch 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. > >Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
Matthias Kohl
2007-Jan-22 06:02 UTC
[R] Integration + Normal Distribution + Directory Browsing Processing Questions
Hi, why don't you use pnorm? E.g., pnorm(1, mean = 0.1, sd = 1.2) - pnorm(0, mean = 0.1, sd = 1.2) Matthias ----- original message -------- Subject: Re: [R] Integration + Normal Distribution + Directory Browsing Processing Questions Sent: Sun, 21 Jan 2007 From: Dimitris Rizopoulos<Dimitris.Rizopoulos at med.kuleuven.be>> you can use the `...' argument of integrate, e.g., > > integrate(dnorm, 0, 1) > integrate(dnorm, 0, 1, mean = 0.1) > integrate(dnorm, 0, 1, mean = 0.1, sd = 1.2) > > look at ?integrate for more info. > > I hope it helps. > > Best, > Dimitris > > ---- > Dimitris Rizopoulos > Ph.D. Student > Biostatistical Centre > School of Public Health > Catholic University of Leuven > > Address: Kapucijnenvoer 35, Leuven, Belgium > Tel: +32/(0)16/336899 > Fax: +32/(0)16/337015 > Web: http://med.kuleuven.be/biostat/ > http://www.student.kuleuven.be/~m0390867/dimitris.htm > > > Quoting Nils Hoeller <mail at nhoeller.de>: > > > Hi everyone, > > > > I am new to R, but it's really great and helped me a lot! > > > > But now I have 2 questions. It would be great, if someone can help me: > > > > 1. I want to integrate a normal distribution, given a median and sd. > > The integrate function works great BUT the first argument has to be a > > function > > > > so I do integrate(dnorm,0,1) and it works with standard m. and sd. > > > > But I have the m and sd given. > > > > So for fixed m and sd I work around with a new function mynorm > > > > mynorm <- function(n) { > > ret <- dnorm(n,0.6,0.15) > > ret > > } > > > > for example. > > > > BUT what can I do for dynamic m and sd? > > I want something like integrate(dnorm(,0.6,0.15),0,1), with the first > > dnorm parameter open for the > > integration but fixed m and sd. > > > > I hope you can help me. > > > > 2. I am working with textfiles with rows of measure data. > > read.table("file") works fine. > > > > Now I want R to read.table all files within a given directory and > > process them one by the other. > > > > for(all files in dir xy) { > > x <- read.table(nextfile) > > process x > > } > > > > Is that possible with R? I hope so. Can anyone give me a link to > examples. > > > > Thanks for your help > > > > Nils > > > > ______________________________________________ > > R-help at stat.math.ethz.ch 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. > > > > > > > > Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm > > ______________________________________________ > R-help at stat.math.ethz.ch 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. >--- original message end ---- -- Dr. rer. nat. Matthias Kohl Matthias.Kohl at stamats.de www.stamats.de
Charilaos Skiadas
2007-Jan-22 06:27 UTC
[R] Integration + Normal Distribution + Directory Browsing Processing Questions
On Jan 21, 2007, at 2:27 PM, Nils Hoeller wrote:> Now I want R to read.table all files within a given directory and > process them one by the other.?list.files ?"for" Haris
Matthias Kohl
2007-Jan-22 08:08 UTC
[R] Integration + Normal Distribution + Directory Browsing Processing Questions
Hi Nils, I would say, pnorm is faster and has a higher precision. Best, Matthias ----- original message -------- Subject: Re: [R] Integration + Normal Distribution + Directory Browsing Processing Questions Sent: Mon, 22 Jan 2007 From: Nils Hoeller<mail at nhoeller.de>> Thank you, > > both work fine. Why is pnorm to prefer? > > Nils > > > Matthias Kohl schrieb: > > Hi, > > > > why don't you use pnorm? > > E.g., > > > > pnorm(1, mean = 0.1, sd = 1.2) - pnorm(0, mean = 0.1, sd = 1.2) > > > > Matthias > > > > ----- original message -------- > > > > Subject: Re: [R] Integration + Normal Distribution + Directory Browsing > Processing Questions > > Sent: Sun, 21 Jan 2007 > > From: Dimitris Rizopoulos<Dimitris.Rizopoulos at med.kuleuven.be> > > > > > >> you can use the `...' argument of integrate, e.g., > >> > >> integrate(dnorm, 0, 1) > >> integrate(dnorm, 0, 1, mean = 0.1) > >> integrate(dnorm, 0, 1, mean = 0.1, sd = 1.2) > >> > >> look at ?integrate for more info. > >> > >> I hope it helps. > >> > >> Best, > >> Dimitris > >> > >> ---- > >> Dimitris Rizopoulos > >> Ph.D. Student > >> Biostatistical Centre > >> School of Public Health > >> Catholic University of Leuven > >> > >> Address: Kapucijnenvoer 35, Leuven, Belgium > >> Tel: +32/(0)16/336899 > >> Fax: +32/(0)16/337015 > >> Web: http://med.kuleuven.be/biostat/ > >> http://www.student.kuleuven.be/~m0390867/dimitris.htm > >> > >> > >> Quoting Nils Hoeller <mail at nhoeller.de>: > >> > >> > >>> Hi everyone, > >>> > >>> I am new to R, but it's really great and helped me a lot! > >>> > >>> But now I have 2 questions. It would be great, if someone can help me: > >>> > >>> 1. I want to integrate a normal distribution, given a median and sd. > >>> The integrate function works great BUT the first argument has to be a > >>> function > >>> > >>> so I do integrate(dnorm,0,1) and it works with standard m. and sd. > >>> > >>> But I have the m and sd given. > >>> > >>> So for fixed m and sd I work around with a new function mynorm > >>> > >>> mynorm <- function(n) { > >>> ret <- dnorm(n,0.6,0.15) > >>> ret > >>> } > >>> > >>> for example. > >>> > >>> BUT what can I do for dynamic m and sd? > >>> I want something like integrate(dnorm(,0.6,0.15),0,1), with the first > >>> dnorm parameter open for the > >>> integration but fixed m and sd. > >>> > >>> I hope you can help me. > >>> > >>> 2. I am working with textfiles with rows of measure data. > >>> read.table("file") works fine. > >>> > >>> Now I want R to read.table all files within a given directory and > >>> process them one by the other. > >>> > >>> for(all files in dir xy) { > >>> x <- read.table(nextfile) > >>> process x > >>> } > >>> > >>> Is that possible with R? I hope so. Can anyone give me a link to > >>> > >> examples. > >> > >>> Thanks for your help > >>> > >>> Nils > >>> > >>> ______________________________________________ > >>> R-help at stat.math.ethz.ch 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. > >>> > >>> > >>> > >> > >> Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm > >> > >> ______________________________________________ > >> R-help at stat.math.ethz.ch 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. > >> > >> > > > > --- original message end ---- > > > > > > -- > > Dr. rer. nat. Matthias Kohl > > Matthias.Kohl at stamats.de > > www.stamats.de > > > > > > ______________________________________________ > R-help at stat.math.ethz.ch 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. >--- original message end ---- -- Dr. rer. nat. Matthias Kohl Matthias.Kohl at stamats.de www.stamats.de
Erich Neuwirth
2007-Jan-22 19:38 UTC
[R] Integration + Normal Distribution + Directory Browsing Processing Questions
Nils Hoeller wrote:> > for example. > > BUT what can I do for dynamic m and sd? > I want something like integrate(dnorm(,0.6,0.15),0,1), with the first > dnorm parameter open for the > integration but fixed m and sd.integrate(function(x)dnorm(x,0.1,1.2), 0, 1) is a way of "fixing" additional parameters. -- Erich Neuwirth, University of Vienna Faculty of Computer Science Computer Supported Didactics Working Group Visit our SunSITE at http://sunsite.univie.ac.at Phone: +43-1-4277-39464 Fax: +43-1-4277-39459