Skip to content

Commit

Permalink
to merge with Stephanie's and Jennifer's updates (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
emilioalaca authored Oct 11, 2018
1 parent 7a79129 commit 49290ec
Show file tree
Hide file tree
Showing 37 changed files with 3,061 additions and 1,504 deletions.
Binary file modified .DS_Store
Binary file not shown.
620 changes: 310 additions & 310 deletions .Rhistory (1)

Large diffs are not rendered by default.

7 changes: 1 addition & 6 deletions 00.1_FrontMatter.Rmd
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
---
<<<<<<< HEAD
title: "PLS 120. Introduction to Applied Statistics"
author: "Emilio A. Laca, Jennifer Brazeal, Cale Miller, Stephanie Zullo"
date: "2018-02-16"
=======
title: "APPLIED STATISTICS IN AGRICULTURAL AND LIFE SCIENCES WITH R"
author: "Emilio A. Laca, Jennifer Brazeal, Cale Miller, Stephanie Zullo"
date: "`r date()`"
>>>>>>> EAL18Sep18
site: bookdown::bookdown_site
documentclass: book
bibliography: [book.bib]
Expand All @@ -20,6 +14,7 @@ output:
fig_caption: true

github-repo: emilioalaca/bookdown-start

url: 'http\://the book url goes here ******'
description: "Course materials for PLS 120. University of California, Davis"
---
Expand Down
14 changes: 7 additions & 7 deletions 02.0_Rcomputation.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ When RStudio is opened, four windows that appear :

- the Terminal or Console window, which is where R computes the command line code you enter,

- the Markdown File window, which is where you can edit and save lines of code and send code to the console to calculate,
- the Source or Markdown File window, which is where you can edit and save lines of code and send code to the console to calculate,

- the Environment and History window, which is where working datasets and objects are listed, and

Expand Down Expand Up @@ -131,7 +131,7 @@ knitr::include_graphics("images/CH2Error.png")
To clear the history in the Console, you can click on the broom button or press "Ctrl" + "L".


### Markdown (Source) Window
### Source (Markdown) Window

The Markdown window is similar to a notepad; this is where you can input and save command line code, include instructions and attach notes. All of the computer labs for this class will have you working with instructions provided in R Markdown, saved in .rmd files. These files will contain written instructions and then "chunks" within the R Markdown file where you can input and send command line code to the Terminal window for computation. The "chunks" will appear as gray lines that always start with three ticks and a lowercase r in brackets and end with another three ticks. See the example below of an empty chunk.

Expand Down Expand Up @@ -193,7 +193,7 @@ This pane will includes all of the files that are currently available in your wo

In the Files tab, you can click on "More" and set your working directory to the desired location on your computer.

```{r Working Directory}
```{r WorkingDirectory}
knitr::include_graphics("images/CH2WD.png")
Expand Down Expand Up @@ -254,7 +254,7 @@ The Environment and History window shows you data and objects that are loaded in

### Vectors and Data Frames

```{r Vectors and Data Frames}
```{r VectorsAndDataFrames}
knitr::include_graphics("images/CH2VectorDataFrame.png")
Expand Down Expand Up @@ -282,7 +282,7 @@ One of the most common way to have data in R is using objects called data frames
Another data structure is a matrix, which is a two-dimensional table. Matrices may look like data frames in their structure, but they are different in that it can only contain one type of data, i.e. a table of numeric values only. Due to this limitation, we will primarily be working with data frames throughout the class.


```{r Data Frames}
```{r DataFrames}
mymatrix <- cbind(myvector, myvector2)
mymatrix
Expand Down Expand Up @@ -315,13 +315,13 @@ read.table() imports .txt files into your Environment
read_excel() imports .xls and .xlsx files into your Environment


```{r Importing Data}
```{r ImportingData}
knitr::include_graphics("images/CH2Import2.png")
```

Another option is to click on the Import Dataset button at the top of the Environment Window tab and to manually select the location of the file. Here you can designate if the file is from Excel or from a Text (readr); the latter will also give you the option to designate if your file is comma (.csv) or tab (.txt) delineated. This will also provide you with code for importing the data, including the complete file path. The code will be provided at the beginning of each lab for how to import the dataset we will be working with.
Another option is to click on the Import Dataset button at the top of the Environment Window tab and to manually select the location of the file. Here you can designate if the file is from Excel or from a Text (readr); the latter will also give you the option to designate if your file is comma (.csv) or tab (.txt) separated. This will also provide you with code for importing the data, including the complete file path. The code will be provided at the beginning of each lab for how to import the dataset we will be working with.



Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed 02.0_Rcomputation_files/figure-html/ps grouped-1.png
Binary file not shown.
Binary file not shown.
Binary file not shown.
57 changes: 41 additions & 16 deletions 03.0_MathSymbols.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,31 @@ output:
theme: readable
toc: yes
toc_depth: 3
editor_options:
chunk_output_type: console
---

```{r setup, echo=FALSE, message=FALSE}
library(kableExtra)
library(knitr)
```


# Required Math Skills and Symbols {#chMath}

In this chapter we introduce most of the mathematics and symbols that are used in the book. We start with the concept and symbols for summation used to represent sums of many numbers generally and succinctly. We use simple numerical examples for which we give the mathematical equations and the corresponding R code to perform the operations. In order to present the symbols in a context that is relevant for the rest of the book, we explore equations for averages and variances, and we present models. At this point, the definitions of mean, variance, etc., and the formulation of specific models are not the main focus, and they will be presented later in more detail.

A **key point** in this chapter is that

```{block, type = 'stattip'}
```{block StatModels, type = 'stattip'}
- In statistics we are always using models, and making those models explicit by writing them down completely is essential to understanding and communicating what we are doing.
```

This chapter develops models of increasing complexity and uses them to present the equations, symbols, and mathematical concepts that are used throughout the rest of the book.

A second **key point**, related to the first one, is that

```{block, type = 'stattip'}
```{block UnknownParameters, type = 'stattip'}
- We rarely, if ever, know the actual "true" value of parameters, variables or quantities in the real world (as opposed to simulations).
```

Expand Down Expand Up @@ -137,7 +145,7 @@ Y_1 + Y_2 + Y_2 + Y_3 + Y_3 + Y_4 \\ \\ &=
\end{equation}
<br>

As usual, there are many ways to achieve a task in R. To perform the sum above we can use the following alternatives:
As usual, there are many ways to complete a task in R. To perform the sum above we can use the following alternatives:

```{r, message=FALSE}
sum(Y[1:3] + Y[2:4])
Expand Down Expand Up @@ -204,9 +212,9 @@ The subscript $i$ refers to rows and $j$ refers to columns. We illustrate this w
\begin{equation}
\mathbf{Y} =
\begin{pmatrix}
Y_{1,1} & Y_{1,2} & Y_{1,3} & Y_{1,4} & Y_{1,5} & Y_{1,6} & Y_{1,7} \\
Y_{2,1} & Y_{2,2} & Y_{2,3} & Y_{2,4} & Y_{2,5} & Y_{2,6} & Y_{2,7} \\
Y_{3,1} & Y_{3,2} & Y_{3,3} & Y_{3,4} & Y_{3,5} & Y_{3,6} & Y_{3,7}
Y_{1,1} & Y_{1,2} & Y_{1,3} & Y_{1,4} & Y_{1,5} & Y_{1,6} & Y_{1,7} \\
Y_{2,1} & Y_{2,2} & Y_{2,3} & Y_{2,4} & Y_{2,5} & Y_{2,6} & Y_{2,7} \\
Y_{3,1} & Y_{3,2} & Y_{3,3} & Y_{3,4} & Y_{3,5} & Y_{3,6} & Y_{3,7}
\end{pmatrix} \\[35pt] =
\begin{pmatrix}
34 & 32 & 27 & 37 & 25 & 23 & 30 \\
Expand Down Expand Up @@ -275,7 +283,7 @@ If we want to average all values in the table, we need to use a double summation
\sum_{j=1}^{j=7}Y_{3j} \right) \\[18pt]

&= \frac{1}{3 \times 7} \ (Y_{11} + Y_{12} + Y_{13} + Y_{14} + Y_{15} + Y_{16} + Y_{17} \\
& \qquad \qquad + Y_{21} + Y_{22} Y_{23} + Y_{24} + Y_{25} + Y_{26} + Y_{27} \\[8pt]
& \qquad \qquad + Y_{21} + Y_{22} + Y_{23} + Y_{24} + Y_{25} + Y_{26} + Y_{27} \\[8pt]
& \qquad \qquad + Y_{31} + Y_{32} + Y_{33} + Y_{34} + Y_{35} + Y_{36} + Y_{37}) \\[20pt]
& = \frac{1}{3 \times 7} \ (34 + 32 + 27 + 37 + 25 + 23 + 30 \\
& \qquad \qquad + 30 + 26 + 26 + 33 + 24 + 22 + 27 \\
Expand Down Expand Up @@ -314,19 +322,22 @@ If we just want the average for corn, we extract just the row for corn (row 2) a
&= \frac{1}{7} (30 + 26 + 26 + 33 + 24 + 22 + 27) = 26.86
\end{aligned}
(\#eq:math11)
\end{equation} \\
\begin{equation}
\end{equation}
<br>

<br>
$$\begin{equation}
\begin{aligned}
&fields \ 3, \ 4, \ 5 \ \& \ 7 \ average = \frac{1}{4 \times 3} \left( \sum_{j=1}^{j=3}Y_{3j} +
\sum_{j=1}^{j=3}Y_{4j} +
\sum_{j=1}^{j=3}Y_{5j} +
\sum_{j=1}^{j=3}Y_{7j} \right) \\[20pt]
&= \frac{1}{4 \times 3} (Y_{31} + Y_{32} + Y_{33} + Y_{41} + Y_{42} + Y_{43} + Y_{51} + Y_{52} + Y_{53} + Y_{71} + Y_{72} + Y_{73}) \\[20pt]
&fields \ 3, \ 4, \ 5 \ \& \ 7 \ average = \frac{1}{4 \times 3} \left( \sum_{i=1}^{i=3}Y_{i3} +
\sum_{i=1}^{i=3}Y_{i4} +
\sum_{i=1}^{i=3}Y_{i5} +
\sum_{i=1}^{i=3}Y_{i7} \right) \\[20pt]
&= \frac{1}{4 \times 3} (Y_{13} + Y_{23} + Y_{33} + Y_{14} + Y_{24} + Y_{34} + Y_{15} + Y_{25} + Y_{35} + Y_{17} + Y_{27} + Y_{37}) \\[20pt]
&= \frac{1}{4 \times 3} (27 + 26 + 24 + 37 + 33 + 34 + 25 + 24 + 23 + 30 + 27 + 26) \\[20pt]
&= \frac{336}{12} = 28.0
\end{aligned}
(\#eq:math12)
\end{equation}
\end{equation}$$
<br>

We obtain those averages in R with the following code. Note that when we leave the place for row (or column) number empty, it is interpreted as all rows (or columns).
Expand Down Expand Up @@ -1207,9 +1218,23 @@ a. What is the response variable of interest? What is the predictor variable of

### Homework Exercise

Qo'noS, the planet of Klingons had an abundant population of targ, which were both wild and domesticated for food. In his highschool years, Worf took a weekend and did a complete census of the Targ population to determine their mass determined by groups. His results are in Table \@ref(tab:TargMass), all expressed in chebs.

<br>
```{r TargMass, echo=FALSE, message=FALSE}
### Homework Exercise
targs <- data.frame(i = 1:6, Group = c("AdultFemale", "AdultMale", "JuvenileFemale", "JuvenileMale", "Yearlings", "Pups"), Mass = c(123, 157, 85, 100, 55, 25))
kable(targs, caption = "Mass per individual of different groups of the population of targs in Qo'noS when Worf did the census.") %>%
kable_styling(full_width = FALSE)
````
<br>
1. Calculate the effect of age-sex group on mass for each group.
1. Compute the sum of square deviations frome each group mean to the overall mean.
1.Write down a model that expresses the mass of a randomly selected targ as a function of a fixed or structural component and a random component. You can include an overall mean if you wish. Use the same type of symbols used in this chapter.
1. Using the overall mean and the group effects as ingredients in columns, construct a table that has the recipies for the mean mass of each group.
Binary file removed 03.0_MathSymbols_files/figure-html/mathPolys-1.png
Binary file not shown.
Binary file removed 03.0_MathSymbols_files/figure-html/propLtMean-1.png
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit 49290ec

Please sign in to comment.