Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
wzbillings committed Jul 15, 2024
2 parents e4cbb7e + 2aa82cb commit b7d7cb6
Show file tree
Hide file tree
Showing 32 changed files with 1,504 additions and 489 deletions.
6 changes: 3 additions & 3 deletions _freeze/modules/Module01-Intro/execute-results/html.json

Large diffs are not rendered by default.

16 changes: 9 additions & 7 deletions _freeze/modules/Module02-Functions/execute-results/html.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
269 changes: 179 additions & 90 deletions docs/modules/Module01-Intro.html

Large diffs are not rendered by default.

382 changes: 245 additions & 137 deletions docs/modules/Module02-Functions.html

Large diffs are not rendered by default.

553 changes: 490 additions & 63 deletions docs/modules/Module09-DataAnalysis.html

Large diffs are not rendered by default.

331 changes: 227 additions & 104 deletions docs/modules/Module10-DataVisualization.html

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/modules/images/help_file.pdf
Binary file not shown.
Binary file added docs/modules/images/help_file.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
330 changes: 283 additions & 47 deletions docs/search.json

Large diffs are not rendered by default.

42 changes: 22 additions & 20 deletions modules/Module01-Intro.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,21 @@ knitr::include_graphics("images/both.png")

## Working with R in RStudio - 2 major panes:

1) The **Source/Editor**: xxamy
1. The **Source/Editor**:

</br>

- "Analysis" Script

- Static copy of what you did (reproducibility)

- Top by default

2) The **R Console**: "interprets" whatever you type:

- Calculator
- Try things out interactively, then add to your editor
- Bottom by default
2. The **R Console**: "interprets" whatever you type:

- Calculator
- Try things out interactively, then add to your editor
- Bottom by default

## Source / Editor

Expand Down Expand Up @@ -178,7 +182,7 @@ You can do basic arithmetic in R, which I surprisingly use all the time.

To execute or run a line of code (i.e., command), you just put your cursor on the command and then:

1. Press Run (which you will find at the top of your window)
1. Press Run (which you will find at the top of your Console pane)

OR

Expand Down Expand Up @@ -276,13 +280,13 @@ I tend to use:
number.object <- 3
character.object <- "blue"
vector.object1 <- c(2,3,4,5)
vector.object2 <- c("blue", "red", "yellow")
vector.object2 <- paste0(c("b", "t", "u"), c(8,4,2))
matrix.object <- matrix(data=vector.object1, nrow=2, ncol=2, byrow=TRUE)
```

Note, `c()` and `matrix()` are functions, which we will talk more about in module 2.
Note, `c()`, `paste0()`, and `matrix()` are functions, which we will talk more about in module 2.

## Object names
## Object names - Good coding

- In general, any object name can be typed into R.
- However, only some are considered "valid". If you use a non-valid object name,
Expand All @@ -295,7 +299,7 @@ you will have to enclose it in backticks \``like this`\` for R to recognize it.
`next`, `break`, `TRUE`, `FALSE`, `NULL`, `Inf`, `NaN`, `NA`, `NA_integer_`,
`NA_real_`, `NA_Complex_`, `_NA_Character`, `...`, `..1`, `..2`, `..3`, and so on.

## Object names
## Object names - Good coding

| Valid | Invalid |
|--------------|---------|
Expand All @@ -305,6 +309,11 @@ you will have to enclose it in backticks \``like this`\` for R to recognize it.
| `measles_data` | `.9data` |
| `.calc` | `xX~mŷ_δätą~Xx` |


## Object assingment - Good coding

`=` and `<-` can both be used for assignment, but `<-` is better coding practice, because sometimes `=` doesn't work and we want to distinguish between the logical operator `==`. We will talk about this more, later.

## Mini Exercise

Try creating one or two of these objects in your R script
Expand All @@ -313,13 +322,13 @@ Try creating one or two of these objects in your R script
number.object <- 3
character.object <- "blue"
vector.object1 <- c(2,3,4,5)
vector.object2 <- c("blue", "red", "yellow")
vector.object2 <- paste0(c("b", "t", "u"), c(8,4,2))
matrix.object <- matrix(data=vector.object1, nrow=2, ncol=2, byrow=TRUE)
```

## Objects

Note, you can find these objects now in the Global Environment.
Note, you can find these objects now in your Environment pane.

```{r, out.width = "90%", echo = FALSE}
knitr::include_graphics("images/global_env.png")
Expand All @@ -336,13 +345,6 @@ character.object
matrix.object
```


# Object names and assingment - Good coding

xxzane

`=` and `<-` can both be used for assignment, but `<-` is better coding practice, because sometimes `=` doesn't work and we want to distinguish between the logical operator `==`. We will talk about this more, later.

## Lists

List is a special data class, that can hold vectors, strings, matrices, models, list of other lists.
Expand Down
30 changes: 22 additions & 8 deletions modules/Module02-Functions.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,15 @@ log(10)
- what arguments a function includes?
- how to specify the arguments?

## Seeking help for using functions
## Seeking help for using functions (*)

The best way of finding out this information is to use the `?` followed by the name of the function. Doing this will open up the help manual in the bottom RStudio Help panel. It provides a description of the function, usage, arguments, details, and examples. Lets look at the help file for the function `round()`

```{r echo=TRUE, eval=FALSE}
?log
```{r, out.width = "70%", echo = FALSE}
knitr::include_graphics("images/help_file.png")
```


```{r, echo = FALSE, results = "asis"}
library(printr)
?log
```

## How to specify arguments

1. Arguments are separated with a comma
Expand Down Expand Up @@ -178,11 +173,30 @@ library(printr)
?c
```

## Functions from Module 1

The `paste0()` function concatenate/combines vectors after converting to character.

```{r echo=TRUE, eval=FALSE}
vector.object2 <- paste0(c("b", "t", "u"), c(8,4,2))
vector.object2
?paste0
```

```{r echo=FALSE}
library(printr)
?paste0
```



## Functions from Module 1

The `matrix()` function creates a matrix from the given set of values.

```{r echo=TRUE, eval=FALSE}
matrix.object <- matrix(data=vector.object1, nrow=2, ncol=2, byrow=TRUE)
matrix.object
?matrix
```

Expand Down
10 changes: 7 additions & 3 deletions modules/Module09-DataAnalysis.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,13 @@ summary(fit2)

## Summary

- Use `cor()` or `cor.test()` to calculate correlation between two numeric vectors.
- `t.test()` tests the mean compared to null or difference in means between two groups
- ... xxamy more
- the `aggregate()` function can be used to conduct analyses across groups (i.e., categorical variables in the data(
- the `table()` function can generate frequency tables for 2 plus variables, but to get percentage tables, the `prop.table()` is useful
- the `chisq.test()` function tests independence of factor variables
- the `cor()` or `cor.test()` functions can be used to calculate correlation between two numeric vectors
- the `t.test()` functions conducts one and two sample (paired or unpaired) t-tests
- the function `glm()` fits generalized linear modules to data and returns a fit object that can be read with the `summary()` function
- changing the `family` argument in the `glm()` function allows you to fit models with different link functions

## Acknowledgements

Expand Down
14 changes: 11 additions & 3 deletions modules/Module10-DataVisualization.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ We will only look at four types of plots today:
- `barplot()` displays barplot


## `histogram()` Help File
## `hist()` Help File

```{r echo=TRUE, eval=FALSE}
?hist
Expand All @@ -138,7 +138,7 @@ library(printr)
?hist
```

## `histogram()` example
## `hist()` example

Reminder function signature
```
Expand Down Expand Up @@ -231,6 +231,7 @@ points(
```

* The `lines()` function works similarly for connected lines.
* Note that the `points()` or `lines()` functions must be called with a `plot()`-style function
* We will show how we could draw a `legend()` in a future section.


Expand Down Expand Up @@ -435,10 +436,17 @@ axis(2, at = c(0.2, 0.4, 0.6, 0.8,1))
legend("topright", fill=c("darkblue","red"), legend = c("seronegative", "seropositive"))
```

## Base R plots vs the Tidyverse ggplot2 package

It is good to know both b/c they each have their strengths

## Summary

-
- the Base R 'graphics' package has a ton of graphics options that allow for ultimate flexibility
- Base R plots typically include setting plot options (`par()`), mapping data to the plot (e.g., `plot()`, `barplot()`, `points()`, `lines()`), and creating a legend (`legend()`).
- the functions `points()` or `lines()` add additional points or additional lines to an existing plot, but must be called with a `plot()`-style function
- in Base R plotting the legend is not automatically generated, so be careful when creating it


## Acknowledgements

Expand Down
Binary file added modules/images/help_file.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b7d7cb6

Please sign in to comment.