Skip to main content
Chemistry LibreTexts

Appendix

  • Page ID
    81722
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    The following R code, with comments, was used to generate the net weights for the 30 samples. The file data.csv was identical in structure to Table 2, but did not include the final column of net weights. This code reads in the original data, calculates the total number of M&Ms in each sample, draws the appropriate number of M&Ms for each sample and calculates the average weight of an M&M in the sample, calculates the net weight of M&Ms in each sample, and adds the net weights to the original data and saves the data as a new file.

    # Create data frame ‘rawdata’ to store data for the samples

    rawdata = read.csv(“data.csv”)

    # Create vector ‘total’ to store number of M&Ms in each sample, calculated

    # by summing, by row (1), the number of M&Ms in columns 3–8 of ‘rawdata’

    total = apply(rawdata[ , 3:8], 1, sum)

    # Create vector ‘avg.weight’ to store average weight of M&Ms in each sample

    avg.weight = seq(1:30)

    # Create separate vectors for the population mean and the standard deviation

    # with values determined using the masses of 462 plain M&Ms available at

    # the Puget Sound Data Hoard (http://stat.pugetsound.edu/hoard/Default.aspx)

    mu = 0.86483

    sig = 0.046199

    # For each sample, calculate the average mass for its M&Ms, with the number

    # of M&Ms defined by the vector ‘total,’ using a random draw from a normal

    # distribution defined by the population’s mean standard deviation

    for (i in 1:30) avg.weight[i] = mean(rnorm(total[i], mu, sig))

    # Find the net weight for each sample by multiplying the number of M&Ms in

    # the sample by the average weight of an M&M in the sample

    net.weight = total * avg.weight

    # Create final data set by adding net.weight to the original data and save

    mmdata = data.frame(rawdata, net.weight)

    write.csv = (mmdata, file = “mmdata.csv”)


    This page titled Appendix is shared under a CC BY-NC-SA 4.0 license and was authored, remixed, and/or curated by Contributor.

    • Was this article helpful?