Skip to content

Commit

Permalink
first draft of resampling finished. need to test it
Browse files Browse the repository at this point in the history
  • Loading branch information
gina committed Oct 25, 2014
1 parent 3897899 commit 94dc950
Show file tree
Hide file tree
Showing 10 changed files with 234 additions and 397 deletions.
2 changes: 1 addition & 1 deletion Statistical_Inference/MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ T_Confidence_Intervals
Hypothesis_Testing
P_Values
Power
Multiple_Testing
Resampling

2 changes: 1 addition & 1 deletion Statistical_Inference/Power/lesson
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@
Hint: Since you're doubling the denominator (sd) you have to double the numerator (delta) in order to keep the effect size constant.

- Class: text
Output: Now for a quick review - we call this the power.u.test LOL
Output: Now for a quick review. We call this the power.u.test since it comes after the power.t.test. LOL.

- Class: mult_question
Output: 1. The level of a test is specified by what?
Expand Down
2 changes: 2 additions & 0 deletions Statistical_Inference/Resampling/fatherson.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
x <- fs$sheight
y <- fs$fheight
n <- length(x)
B <- 10000
resamples <- matrix(sample(x,
Expand All @@ -11,3 +12,4 @@ g = g + geom_density(size = 2, fill = "red")
#g = g + geom_histogram(alpha = .20, binwidth=.3, colour = "black", fill = "blue", aes(y = ..density..))
g = g + geom_vline(xintercept = median(x), size = 2)
print(g)

1 change: 1 addition & 0 deletions Statistical_Inference/Resampling/initLesson.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
library(ggplot2)
fname <- paste(getwd(),"Statistical_Inference/Hypothesis_Testing/father_son.csv",sep="/")
fs <- read.csv(fname)
data(InsectSprays)
5 changes: 5 additions & 0 deletions Statistical_Inference/Resampling/insectHisto.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
g = ggplot(data.frame(perms = perms),
aes(permutations))
g = g + geom_histogram(fill = "lightblue", color = "black", binwidth = 1)
g = g + geom_vline(xintercept = obs, size = 2)
print(g)
12 changes: 12 additions & 0 deletions Statistical_Inference/Resampling/insectSprays.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
g = ggplot(InsectSprays, aes(spray, count, fill = spray))
g = g + geom_boxplot()
print(g)
subdata <- InsectSprays[InsectSprays$spray %in% c("B", "C"),]
Bdata <- subdata[subdata$spray=="B",]
Cdata <- subdata[subdata$spray=="C",]
group <- as.character(subdata$spray)
testStat <- function(w, g) mean(w[g == "B"]) - mean(w[g == "C"])
BCcounts <- subdata$count
obs <- testStat(BCcounts, group)


12 changes: 12 additions & 0 deletions Statistical_Inference/Resampling/insectSprays2.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
g = ggplot(InsectSprays, aes(spray, count, fill = spray))
g = g + geom_boxplot()
print(g)
subdata <- InsectSprays[InsectSprays$spray %in% c("D", "E"),]
Ddata <- subdata[subdata$spray=="D",]
Edata <- subdata[subdata$spray=="E",]
group <- as.character(subdata$spray)
testStat <- function(w, g) mean(w[g == "D"]) - mean(w[g == "E"])
DEcounts <- subdata$count
obs <- testStat(DEcounts, group)


589 changes: 196 additions & 393 deletions Statistical_Inference/Resampling/lesson

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion Statistical_Inference/Resampling/plot1.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ nosim <- 1000
cfunc <- function(x, n) mean(x)
g1 = ggplot(data.frame(y = rep(1/6, 6), x = 1 : 6), aes(y = y, x = x))
g1 = g1 + geom_bar(stat = "identity", fill = "lightblue", colour = "black")

#print(g1)
dat <- data.frame(x = apply(matrix(sample(1 : 6, nosim * 50, replace = TRUE),
nosim), 1, mean))
g2 <- ggplot(dat, aes(x = x)) + geom_histogram(binwidth=.2, colour = "black", fill = "salmon", aes(y = ..density..))
print(g2)
#grid.arrange(g1, g2, ncol = 2)

3 changes: 2 additions & 1 deletion Statistical_Inference/Resampling/plot2.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ resampledMeans = apply(resamples, 1, mean)
g1 <- ggplot(as.data.frame(prop.table(table(x))), aes(x = x, y = Freq)) + geom_bar(colour = "black", fill = "lightblue", stat = "identity")
g2 <- ggplot(data.frame(x = resampledMeans), aes(x = x)) + geom_histogram(binwidth=.2, colour = "black", fill = "salmon", aes(y = ..density..))
#grid.arrange(g1, g2, ncol = 2)
print(g1)
print(g1)

0 comments on commit 94dc950

Please sign in to comment.