pnorm qnorm
TRANSCRIPT
![Page 1: pnorm qnorm](https://reader036.vdocuments.us/reader036/viewer/2022082509/58886abb1a28abad0d8b66fd/html5/thumbnails/1.jpg)
title: "Calculating Percentiles / cut off values /"
author: "Martin Kennedy"
date: "February 17, 2016"
Suppose a normal distribution of a test score with mean = 21 and standard deviation = 5...
What percentile is 24?
pnorm(24, mean = 21, sd = 5)
S'pose a person scores in top 10% on SAT
Given mean SAT = 1500, SD = 300
What is lowest possible score that person could have achieved? (use 'qnorm for percentile or cutoff value)
qnorm(0.9, mean = 1500, sd = 300)
... or simply...
qnorm(0.9,1500, 300)
Suppose a person scored in bottom 10% with...
mean ACT = 21, standard dev = 5
What is highest score she could have gotten? Get cutoff value...
qnorm(0.1, mean = 21, sd = 5)
STOP HERE...
![Page 2: pnorm qnorm](https://reader036.vdocuments.us/reader036/viewer/2022082509/58886abb1a28abad0d8b66fd/html5/thumbnails/2.jpg)
Code below uses data from Kobe Bryant and investigates the 'hot-hand' phenomenon by using simulation...
# Load the data frame (data called 'kobe')... use 'head' and / or 'tail' to check data...
load(url("http://s3.amazonaws.com/assets.datacamp.com/course/dasi/kobe.RData"))
head(kobe)
tail(kobe)
# print first 9 obs in data frame 'kobe'...
kobe[1:9,]
names(kobe)
kobe$basket[1:9]
# shooting sreak... number of baskets made until a miss
# The 'kobe' data frame is already loaded into the workspace. Assign Kobe's
# streak lengths:
kobe_streak = calc_streak(kobe$basket)
# Draw a barplot of the result:
barplot(table(kobe_streak))
![Page 3: pnorm qnorm](https://reader036.vdocuments.us/reader036/viewer/2022082509/58886abb1a28abad0d8b66fd/html5/thumbnails/3.jpg)
# if there is a 'hot-hand' phenomenon... then prob a 'make' increases (relavitive to shooting percentage
# GIVEN that he 'made' previous shot... Then events (aka shots) are NOT independent events...
# Try some simulations! Next line simulates a coin flip where function 'c' reps 'coin'...
outcomes = c("heads", "tails")
# with one flip... w / replacement... think of pulling slips of paper from hat with 'H' or 'T' ... 'replace=TRUE'
sample(outcomes, size=1,replace=TRUE)
# Try 100 'flips'
outcomes = c("heads", "tails")
sim_fair_coin = sample(outcomes, size = 100, replace = TRUE)
# Print the object:
sim_fair_coin
# Compute the counts of heads and tails:
table(sim_fair_coin)
# Run 'unfair' coin simulation:
outcomes = c("heads", "tails")
![Page 4: pnorm qnorm](https://reader036.vdocuments.us/reader036/viewer/2022082509/58886abb1a28abad0d8b66fd/html5/thumbnails/4.jpg)
sim_unfair_coin = sample(outcomes, size = 100, replace = TRUE, prob = c(0.2,0.8)) 0.8))
# Print the object:
sim_unfair_coin
# Compute the counts of heads and tails:
table(sim_unfair_coin)
# Run the simulation, to be comparted later with the 'kobe' data... 133 shots on basket... same percentages
# assign it to variable 'sim_basket'
outcomes = c("H", "M")
sim_basket = sample(outcomes, size = 133, replace = TRUE, prob = c(0.45,0.55))
sim_basket
table(sim_basket)