# 1.9 - Summary of important R code

by

The main components of R code used in this chapter follow with components to modify in red, remembering that any R packages mentioned need to be installed and loaded for this code to have a chance of working:

- ◦ Provides numerical summaries of all variables in the data set.

- ◦ Provides two-sample t-test test statistic, df, p-value, and 95% confidence interval.

- ◦ Finds the two-sided test p-value for an observed 2-sample t-test statistic of Tobs.

- ◦ Makes a histogram of a variable named Y from the data set of interest.

- ◦ Makes a boxplot of a variable named Y for groups in X from the data set.

- ◦ Makes a beanplot of a variable named Y for groups in X from the data set.
- ◦ Requires the beanplot package is loaded.

- ◦ Provides the mean and sd of responses of Y for each group described in X.

- ◦ Provides numerical summaries of Y by groups described in X.

B<-1000

Tstar<-matrix(NA,nrow=B)

for (b in (1:B)){

Tstar[b]<-t.test(Y~shuffle(X),data=DATASETNAME,var.equal=T)$statistic

}

- ◦ Code to run a for loop to generate 1000 permuted versions of the test statistic using the shuffle function and keep track of the results in Tstar.

- ◦ Finds the proportion of the permuted test statistics in Tstar that are less than -|Tobs| or greater than |Tobs|,

B<-1000

Tstar<-matrix(NA,nrow=B)

for (b in (1:B)){

Tstar[b]<-compareMeans(Y~X,data=resample(DATASETNAME))

}

- ◦ Code to run a 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.

- ◦ Provides the values that delineate the middle 95% of the results in the bootstrap distribution (Tstar).