Beruflich Dokumente
Kultur Dokumente
R Tutorial
Cyclismo.org
The first function we look at it dnorm. Given a set of values it returns the height of the probability distribution at each point. If you only give the points it assumes you want to use a mean of zero and standard deviation of one. There are options to use different values for the mean and standard deviation, though:
>dom0 nr() []03843 1 .992 >dom0*qt2p) nr()sr(*i []1 1 >dom0ma=) nr(,en4 []000380 1 .01332 >dom0ma=,d1) nr(,en4s=0 []00620 1 .3871 > < c012 v - (,,) >domv nr() []03842 02177 00399 1 .9928 .4902 .5907 >x< sq-02,y.) - e(2,0b=1 >y< domx - nr() >po(,) ltxy >y< domxma=.,d01 - nr(,en25s=.) >po(,) ltxy
The second function we examine is pnorm. Given a number or a list it computes the probability that a normally distributed random number will be less than that number. This function also goes by the rather ominous title of the "Cumulative Distribution Function." It accepts the same options as dnorm:
>pom0 nr() []05 1 . >pom1 nr()
www.cyclismo.org/tutorial/R/probability.html 1/6
15/04/2012
[]08147 1 .434 >pom0ma=) nr(,en2 []00251 1 .2703 >pom0ma=,d3 nr(,en2s=) []02295 1 .542 >v< c012 - (,,) >pomv nr() []050000814709749 1 .000 .434 .729 >x< sq-02,y.) - e(2,0b=1 >y< pomx - nr() >po(,) ltxy >y< pomxma=,d4 - nr(,en3s=) >po(,) ltxy
The next function we look at is qnorm which is the inverse of pnorm. The idea behind qnorm is that you give it a probability, and it returns the number whose cumulative distribution matches the probability. For example, if you have a normally distributed random variable with mean zero and standard deviation one, then if you give the function a probability it returns the associated Z-score:
>qom05 nr(.) []0 1 >qom05ma=) nr(.,en1 []1 1 >qom05ma=,d2 nr(.,en1s=) []1 1 >qom05ma=,d2 nr(.,en2s=) []2 1 >qom05ma=,d4 nr(.,en2s=) []2 1 >qom02,en2s=) nr(.5ma=,d2 []06125 1 .500 >qom033 nr(.3) []-.364 1 04142 >qom033s=) nr(.3,d3 []-.993 1 1243 >qom07,en5s=) nr(.5ma=,d2 []6388 1 .49 >v=c010307) (.,.,.5 >qomv nr() []-.851 -.240 06488 1 12156 05405 .749 >x< sq01b=0) - e(,,y.5 >y< qomx - nr() >po(,) ltxy >y< qomxma=,d2 - nr(,en3s=) >po(,) ltxy >y< qomxma=,d01 - nr(,en3s=.) >po(,) ltxy
The last function we examine is the rnorm function which can generate random numbers whose distribution is normal. The argument that you give it is the number of random numbers that you want, and it has optional arguments to specify the mean and standard deviation:
>rom4 nr() [] 12821-.335 -.038 -.788 1 .377 02229 12001 16143 >rom4ma=) nr(,en3 []2638 3678 2086 2613 1 .300 .146 .381 .093 >rom4ma=,d3 nr(,en3s=) []4505 2940 4769 6359 1 .856 .793 .507 .984 >rom4ma=,d3 nr(,en3s=) [] 3005 3748 1.301 3256 1 .082 .110 0022 .967 >y< rom20 - nr(0) >hs() ity >y< rom20ma=2 - nr(0,en-) >hs() ity >y< rom20ma=2s=) - nr(0,en-,d4 >hs() ity >qnr() qomy >qln() qiey
www.cyclismo.org/tutorial/R/probability.html
2/6
15/04/2012
The t Distribution
There are four functions that can be used to generate the values associated with the t distribution. You can get a full list of them and their options using the help command:
>hl(Ds) epTit
These commands work just like the commands for the normal distribution. One difference is that the commands assume that the values are normalized to mean zero and standard deviation one, so you have to use a little algebra to use these functions in practice. The other difference is that you have to specify the number of degrees of freedom. The commands follow the same kind of naming convention, and the names of the commands are dt, pt, qt, and rt. A few examples are given below to show how to use the different commands. First we have the distribution function, dt:
>x< sq-02,y.) - e(2,0b=5 >y< d(,f1) - txd=0 >po(,) ltxy >y< d(,f5) - txd=0 >po(,) ltxy
15/04/2012
can get a full list of them and their options using the help command:
>hl(ioil epBnma)
These commands work just like the commands for the normal distribution. The binomial distribution requires two extra parameters, the number of trials and the probability of success for a single trial. The commands follow the same kind of naming convention, and the names of the commands are dbinom, pbinom, qbinom, and rbinom. A few examples are given below to show how to use the different commands. First we have the distribution function, dbinom:
>x< sq05,y1 - e(,0b=) >y< dio(,002 - bnmx5,.) >po(,) ltxy >y< dio(,006 - bnmx5,.) >po(,) ltxy >x< sq010b=) - e(,0,y1 >y< dio(,0,.) - bnmx1006 >po(,) ltxy
These commands work just like the commands for the normal distribution. The first difference is that it is assumed that you have normalized the value so no mean can be specified. The other difference is that you have to specify the number of degrees of freedom. The commands follow the same kind of naming convention, and
www.cyclismo.org/tutorial/R/probability.html 4/6
15/04/2012
the names of the commands are dchisq, pchisq, qchisq, and rchisq. A few examples are given below to show how to use the different commands. First we have the distribution function, dchisq:
>x< sq-02,y.) - e(2,0b=5 >y< dhs(,f1) - ciqxd=0 >po(,) ltxy >y< dhs(,f1) - ciqxd=2 >po(,) ltxy
The previous tutorial is a description of the basic operations. The next tutorial is a description of basic plots. Go back to the main page. This tutorial written by Kelly Black. This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike2.5 License.
www.cyclismo.org/tutorial/R/probability.html
5/6
15/04/2012
Splunk Syslog Server Analyze logs, configurations & more with Splunk. Free Download! www.splunk.com/ITSearch Direct Mail Corporation Fulfilment Print & Mailing Experts Enviro Magazine Wrapping - CALL NOW
www.directmail.com.au
VicSuper Finance Tips Super Woman Money. financial tips From our all-female money experts! www.superwomanmoney.com/experts
www.cyclismo.org/tutorial/R/probability.html
6/6