ExampleR8code.docx

#To deal with brand-name distributions, Gaussian, binomial,etc. dname=density or Pr at a #particular value of x; pname=cumulative Pr below a given value of x; qname= quantile #corresponding to a give Pr below (%tile)

#Say we have a Normal (mean=120, sd=8.5) #Say we want density above systolic of 134

dnorm(134,120,8.5)

#[1] 0.01208964

#Want Pr of b.p. below 139

pnorm(139,120,8.5)

#[1] 0.987301

#Want Pr above 143

#1-pnorm(143,120,8.5)

#[1] 0.003406159

#Want 75th %tile

qnorm(0.75,120,8.5)

#[1] 125.7332

#Binomial is trouble because it is discrete

# Say want Pr(16 successes, 18 trials, p=0.83), not in a table

dbinom(16,18,0.83)

#[1] 0.2243049

pbinom(16,18,0.83) #cumulative Pr (x<or=16)

#[1] 0.8362139

#Suppose we want Pr(more than 12 successes, 18 trials, p=0.83) YUCK!

#Should be 1-Pr(x<or=12, cumulative)

1-pbinom(12,18,0.83)

#[1] 0.9292401

Should be 1-Pr(x<or=12, cumulative)

#Error: unexpected symbol in "Should be"