require(mosaic)
require(Tintle1)

Chapter 1: Significance

Chapter 2: Generalization

G <- data.frame(word=GettysburgAddress, stringsAsFactors=FALSE)
G %>% mutate( nchar = nchar(word), e=grepl("e", word)) -> G
histogram(~nchar, data=G, width=1)
histogram(~ result, data = simulation.time, groups = (result <= 6.29 | result >= 13.71),
  nint = 20, center = 10, fit = "t")

Is this not the way to fit a t-distribution on a histogram? Should I add a plot instead?

Chapter 3: Estimation

cdata(0.95, prop, data = simulation.amer)

Is this using a distribution of some type (i.e. normal)? or is it counting 950/1000 of the proportions in the middle of the simulation and giving the lower and higher limit values? Or is it something else completely?

Chapter 4: Causation

Chapter 5: Comparing Two Proportions

prop.test(Response ~ Year, data = Blood)

I cannot seem to change the level to "donated" (nor can I change the alternative to one-sided tests and the conf.levels for the CIs)

prop.test(Response ~ Year, data = Blood)

and instead just doing this for all of the difference in prop tests:

success <- c(230, 210)
n <- c(1336, 1362)
prop.test(success, n)

so that I can easily manipulate the levels, one-sided tests, and conf.levels (although for the simulations I would continue to have to use specified levels?).

(Those last two questions are a handful so if you didn't understand me, I can ask you when we talk in person. Also, chapter 5 is a mess right now because I wasn't checking whether the hypotheses matched the defaults so I wouldn't look too closely that all of the examples.)

Updated questions

Preliminaries

game <- do(1000) * rflip(n = 10, prob = 1/3)    # 1000 samples, each of size 200 and proportion 1/3
head(game)

type = "l" - How would you do the Monty Hall problem in R? The above is a game picking one out of three doors. Tintle does the actual problem where after you pick one out of three doors, a goat is revealed in one of the two you don't pick. Then I'd simulate the success after the switch. (pp.15)

Chapter 1

Chapter 2

Chapter 6

Chapter 7

Chapter 8

More questions

Chapter 2

To get it into the package, it needs to go into Package/data/. I've added it:

head(Pop)

Chapter 5

relrisk(tally(~ Perception + Wording, data = GoodandBad))

will not return the correct relative risk. "the proportion with a positive perception is 2.49 times higher in the 'good year' group than the 'bad year' group" (Example 5.1). I can't figure out what value the function is returning because no conditional proportion ratio matches the one give by the function. Am I doing this incorrectly?

tally(~ Perception + Wording, data = GoodandBad, margins=TRUE)
4/19 / (8/11)
relrisk(tally(~ Perception + Wording, data = GoodandBad))
3/18 / (8/12)
relrisk(tally(~ Wording + Perception, data = GoodandBad))
relrisk(tally( Wording ~ Perception, data=GoodandBad, format="count") )
15/18 / (4/12)

Chapter 7

Example 7.2 and includes simulation in difference in mean by shuffling (not paired). How to do this with data organized for paired? (please see dataset "FirstBase"")

Two solutions:

require(tidyr)
FirstBase %>% gather(angle, time) %>% head()
t.test(time ~ angle, data = FirstBase %>% gather(angle, time))
t.test(FirstBase$narrow, FirstBase$wide)

I guess I like the first one better.

Questions on Chapter 8-10

Chapter 8

acu.table <- tally(~ Improvement + Acupunture, data = Acupuncture)
acu.table
chisq.test(acu.table)
xchisq.test(Towels)

Chapter 9

MAD(mean(BrainChange ~ Treatment, data = Brain))
confint(lm(Recall ~ Condition, data = Recall))

results in the CI of Before-After and None-After. Is there any way to get the CI of Before-None?

Chapter 10

xyplot(size ~ year, data = PlateSize, type = c("p", "r"))
resid(lm(size ~ year, data = PlateSize))
deviance(lm(height ~ footlength, data = FootHeight))
sim.ratet <- do(1000) * coef(summary(lm(shuffle(HeartRate) ~ BodyTemp, data = TempHeart)))
head(sim.ratet, 10)

This is what I tried but the problem is that R is also giving me the t-stat for the interval. Is there any other way to simulate the t-stat or to do analysis (make a dotplot and find the p-val) with the t-stat of just the slope?



rpruim/ISIwithR documentation built on May 28, 2019, 1:30 a.m.