## Introduction  

### Who am I?  

#### **Mr. (almost Dr.!) Richard E.W. Berl**  
<big>(but "Ricky" is fine)</big>  

<big>_I am an evolutionary social (data) scientist with a background in behavior and cultural change and a passion for conserving biocultural diversity and improving social good and environmental sustainability._</big>

<br>

#### **B.A. Biological Sciences & B.A. Anthropology from [University of Delaware](https://www.udel.edu/) (2009)**  

![](./resources/udel_bidenrally.jpg){width="560"}  

<br><br>

#### **Field Assistant, [Lomas Barbudal Monkey Project](http://www.sscnet.ucla.edu/anthro/faculty/sperry/) (2009-2010)**  

* Lomas Barbudal Biological Reserve, Guanacaste, Costa Rica  

    ![](./resources/lomas_map.jpg){width="560"}  
    * Source: [UCLA Anthropology Lomas Barbudal Monkey Project](https://lbmp.anthro.ucla.edu/)  

    &nbsp;  
    
    ![](./resources/me_lomas.jpg){width="560"}  

<br>

* Social learning and behavioral traditions  

    <iframe width="560" height="315" src="https://www.youtube-nocookie.com/embed/Q74BB7aJWH0?rel=0" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>

<br>

* Short documentary: _Family Trees_ by [Prehensile Productions](http://www.prehensileproductions.com/)  

    <iframe width="560" height="315" src="https://www.youtube-nocookie.com/embed/pmDqI4s1VXY?rel=0" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>

<br><br>

#### **M.S. Zoology from [Washington State University](https://wsu.edu/) (2015)**  

* Social behavior and learning in captive gray wolves (_[Canis lupus](https://eol.org/pages/328607)_) at [Wolf Park](http://wolfpark.org/) in Battle Ground, IN  

    ![](./resources/me_wolfpark.jpg){width="560"}  
<!-- end of list -->

    <iframe width="560" height="315" src="https://www.youtube-nocookie.com/embed/MHat4rzkkv8?rel=0" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
        
    <iframe width="560" height="315" src="https://www.youtube-nocookie.com/embed/8Xqf42JD1Mo?rel=0" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
    
<br>

* Social behavior in wild gray wolves (_[Canis lupus](https://eol.org/pages/328607)_) in [Yellowstone National Park](https://www.nps.gov/yell/learn/nature/wolves.htm)  

    <iframe width="560" height="315" src="https://www.youtube-nocookie.com/embed/gaXEDcMypBA?rel=0" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
        
<br>

* Overimitation in non-Western Central African societies  

    ![](./resources/aka.jpg){width="560"}  
    * Source: [Washington State University, Vancouver, Department of Anthropology](https://anthro.vancouver.wsu.edu/people/hewlett/bagandou-central-african-republic/)  
    
    &nbsp;  

    * **Berl, R.E.W.** & Hewlett, B.S. 2015. Cultural variation in the use of overimitation by the Aka and Ngandu of the Congo Basin. PLOS ONE 10(3): e0120180. doi: [10.1371/journal.pone.0120180](https://journals.plos.org/plosone/article?id=10.1371/journal.pone.0120180)

        **Number of irrelevant actions by group and demonstration condition.**  

        ![](./resources/overimitation_figure2.jpg){width="560"}  

<br>

* Cultural and genetic variation of the Chabu hunter-gatherers of Southwestern Ethiopia  

    ![](./resources/me_chabu.jpg){width="560"}  

    &nbsp;  

    * Gopalan, S., **Berl, R. E. W.**, Belbin, G., Gignoux, C., Feldman, M. W., Hewlett, B. S., & Henn, B. M. (2019). Hunter-gatherer genomes reveal diverse demographic trajectories following the rise of farming in East Africa [preprint]. bioRxiv, 517730. Available: https://www.biorxiv.org/node/152746.abstract  

        **Global ancestry proportions of northeast African individuals.**  

        ![](./resources/chabu_figure1.png){width="808"}  

        &nbsp;  

        **Effective migration surfaces depicted as contour lines over A) satellite imagery, B) elevation and water features, and C) the geographic distribution of major language families in Eastern Africa.**  

        ![](./resources/chabu_figureS2.png){height="315"}  

<br><br>

#### **Ph.D. Human Dimensions of Natural Resources from [Colorado State University](https://www.colostate.edu/) (2019)**  

* Ph.D. Candidate in [Human Dimensions of Natural Resources](https://warnercnr.colostate.edu/hdnr/) (defending on May 15th!)

* [Graduate Certificate in Applied Statistics](http://statistics.colostate.edu/graduate-certificate-in-theory-applications-of-regression-models/)

* Influence of **_prestige_** in determining what people learn and from whom they choose to learn

    &nbsp;  

    **Prestige domain item loadings from exploratory factor analysis of attitudinal data.**  

    ![](./resources/prestige_efa.jpg){width="560"}  

    &nbsp;  

    **Determinants of prestige by level of social stratification across 16 societies.**  

    ![](./resources/prestige_edet.jpg){width="808"}  

    &nbsp;  
    
    **Mean proportion of propositions recalled from artificial creation stories by type of content bias and by speaker prestige.**  

    ![](./resources/prestige_biases.jpg){width="808"}  

    &nbsp;  

    **Color matrices of propositions recalled from artificial creation stories.**  

    ![](./resources/prestige_matrix.jpg){width="560"}  

<br>

* Volunteer data scientist for Trees, Water & People

    &nbsp;  

    **Random forest prediction of _Pinus ponderosa var. scopulorum_ habitat suitability under present conditions on Pine Ridge Reservation and Trust Land.**  

    ![](./resources/pineridge_present.jpg){width="808"}  

    &nbsp;  

    **Correlation matrix heatmap of climatic and soil variables.**  

    ![](./resources/pineridge_corr.jpg){width="560"}  

    &nbsp;  
    
    **Logistic regression of _Pinus ponderosa var. scopulorum_ occurrence on burn area.**  

    ![](./resources/pineridge_burn.jpg){width="560"}  


<br><br>


### What we will cover in this course

* **See the [Syllabus](../syllabus_spring2019.html) and [Course Schedule](../schedule_spring2019.html)**  

* **Objectives (from [Syllabus](../syllabus_spring2019.html))**  

    * Set up a convenient computing workflow  

    * Write clean, thoroughly commented R code  

    * Recognize different types of data, how they are measured, and how they are
    handled in R  

    * Use the principle of 'tidy data' to effectively clean and format messy
    data sets  

    * Creatively explore data sets with descriptive statistics and rough
    visualizations prior to confirmatory analyses  

    * Clearly communicate results by visualizing data simply and effectively and
    by telling a compelling story with data  

    * Conduct basic statistical tests and linear regression modeling  

    * Explore advanced topics in data analysis, including dimensionality
    reduction and structural equation modeling  

    * Utilize R for your own research by developing a research question,
    collecting and wrangling data, and conducting the appropriate analyses  

    * Support reproducible research by documenting and embedding analyses in a
    written report  

    * Use the skills you have learned to communicate your process and results to
    a general audience  


<br>


### What we will not cover

* R Markdown (_kind of_) and R Notebook  

* LaTeX  

* Version control  
    * Git / GitHub  

        <!-- end of list -->

* Tibbles (`tibble` package) and piping (`magrittr` package)  

* Statistical theory (_except when necessary_)

<br>

## Setting up a computing workflow

Good organization will save you time and frustration. Future you will thank present you. Trust me. You will have analyses that you'll come back to years later and wonder what in the world you were thinking. It also makes collaborative work a whole lot easier when your work is organized.

See the required reading by FitzJohn and their recommendations for organizing a project. Do it for this class and use it to help organize your own research projects, as well. The earlier, the better.

Create a folder structure for this course. I'd recommend something like the following:

```{r, eval=FALSE}
nr592/
├── data/
├── docs/
├── figs/
├── output/
└┬─ R/
 ├─ assignment1.R
 └─ lecture01.R
```

You may want to create another folder, like `lectures\`, to keep my R Markdown lecture files in (the `lecture01.R` in the structure above refers to your own notes). Or you could put them in `docs\`.

All of the above are just suggestions. Do what makes sense to you and stick with it.

Now we're going to create an R project file for the course. You should put it in your main class folder, like this:

```{r, eval=FALSE}
nr592/
├── data/
├── docs/
├── figs/
├── output/
├── R/
└── nr592.Rproj
```

Use the button in the top right that says "Project: (None)" and select "New Project..." Choose "Existing Directory" if you've already made the class folder, as above. Navigate to the class folder and hit "Create Project."

You're done! Any time you need to work on something for this class, you can open this project and any scripts you had open last time will open up for you.

Importantly, your working directory (the directory where R will look for any files you're loading or saving) is set to your class directory while you are working on scripts in your R project.

You can check your working directory at any time by running:

```{r}
getwd()
```

(This is my current working directory.)

And if you need to change it, you can do so using `setwd()` with the full folder path inside quotes, inside the parentheses, like so:

`setwd("C:/My Research/My Big Project/")`

(Note the direction of the slashes.)


<br>


## Basic concepts in R

<big>**DON'T BE AFRAID TO FAIL!**</big>

Type something and run it! It doesn't matter if you get an error; you won't break anything.

Run current line/selection of code:  

* Ctrl+Enter (Windows)  
* Command+Enter (Mac)  

Clear console:  

* Ctrl+L (Windows & Mac)  

Source: [RStudio Keyboard Shortcuts](https://support.rstudio.com/hc/en-us/articles/200711853-Keyboard-Shortcuts)

### Objects

#### Variables

**Assignment**

```{r}
a = 1
b = 2
c = 42
```

```{r}
a
b
c
```

Assignment can also be done using the `<-` operator (i.e. `c <- 42`). I like using `=` because it uses fewer keystrokes and is more similar to other programming languages, like Python. You can use either, just pick one and stick with it.

If you use `=`, keep in mind that `=` is used for assignment and `==` is used for logical comparisons, i.e. "Does `a == 7`? `FALSE`".

If you use `<-`, the direction of the arrow matters: `c <- 42` is the same as `42 -> c`, but is different from `c -> 42`. You can also assign a value to multiple variables at once with this operator, i.e. `g <- h <- i <- 6`.

**Operations**

```{r}
a + b
a^2 + b^2
c / (a + b)
```

Spacing doesn't matter.

```{r}
c / (a                                                                     +b )
```

You can even hit 'Enter'/'Return' in a script (see below) and carry on to the next line.

```{r}
(a - c) +
  (a * b) +
  (c / b)
```

Or leave empty lines between commands (though you wouldn't want to do this in the middle of a command--it would be confusing and _bad stuff_ could happen).

```{r, eval=FALSE}
a + b + c - b^2




c * 2
```

(This code block wasn't evaluated so that you could actually see the spacing, but it works! Try it.)

Use spacing to your advantage to make your code more easily readable. If you have a line of code that goes over 80 characters (the thin line on the right side of your script pane), insert returns after operators (+, -, etc.) for clean breaks in your code. R will auto-indent the next line for you.

### Scripts

**Always work in scripts!**

Open a new R script:

* Ctrl+Shift+N (Windows)  
* Command+Shift+N (Mac)  

Source: [RStudio Keyboard Shortcuts](https://support.rstudio.com/hc/en-us/articles/200711853-Keyboard-Shortcuts)


<br><br>


([pdf](./lecture01.pdf) / [Rmd](./lecture01.Rmd))

<div class="tocify-extend-page" data-unique="tocify-extend-page" style="height: 0;"></div>