The main components of R code used in this chapter follow with components to modify in lighter and/or ALL CAPS text, remembering that any R packages mentioned need to be installed and loaded for this code to have a chance of working:
summary(DATASETNAME)
summary(lm(Y ~ X, data=DATASETNAME))
confint(lm(Y ~ X, data=DATASETNAME), level=0.95)
2*pt(abs(Tobs), df=DF, lower.tail=F)
Tobs. hist(DATASETNAME$Y)
Y from the data set of
interest.boxplot(Y~X, data=DATASETNAME)
pirateplot(Y~X, data=DATASETNAME, inf.method=“ci”)
Requires the yarrr package is loaded.
Makes a pirate-plot of a variable named Y for groups in X from the data set with estimated means and 95% confidence intervals for each group.
mean(Y~X, data=DATASETNAME); sd(Y~X, data=DATASETNAME)
This usage of mean and sd requires the mosaic package.
Provides the mean and sd of responses of Y for each group described in X.
favstats(Y~X, data=DATASETNAME)
Tobs <- coef(lm(Y~X, data=DATASETNAME))[2]; Tobs
B <- 1000
Tstar <- matrix(NA, nrow=B)
for (b in (1:B)){
lmP <- lm(Y~shuffle(X), data=DATASETNAME)
Tstar[b] <- coef(lmP)[2]
}
for loop to generate 1000 permuted versions of the test
statistic using the shuffle function and keep track of the results in
Tstarpdata(Tstar, abs(Tobs), lower.tail=F)[[1]]
Tobs <- coef(lm(Y~X, data=DATASETNAME))[2]; Tobs
B <- 1000
Tstar <- matrix(NA, nrow=B)
for (b in (1:B)){
lmP <- lm(Y~X, data=resample(DATASETNAME))
Tstar[b] <- coef(lmP)[2]
}
for loop to generate 1000 bootstrapped versions of the
data set using the resample function and keep track of the results of
the statistic in Tstar.qdata(Tstar, c(0.025, 0.975))
Tstar).