# R for Statistics and Data Visualization

# 1. Lecture Time and Location

- Time: 14:00 - 16:50, Each Friday
- Location: 501, Main Building South

# 2. Prerequisites

Students of this course should be familiar with the basic concepts used in statistics, such as *Mean*, *Standard Deviation*, *Normal Distribution*, *t-statistic*, *ANOVA*, *F-ratio*, *p-value*, *Hypothesis Testing* etc. To acheive this, Students should have already finished some introductory courses in statistics, such as Statistics for the Behavioral Sciences, or other courses at the same level. Students can also learn these basic concepts by themselves.

# 3. Course Information

R is a language and environment for **statistical computing** and **graphics**. It is a GNU project which is similar to the S language and environment which was developed at Bell Laboratories by John Chambers and colleagues. R provides a wide variety of statistical (linear and nonlinear modeling, classical statistical tests, time-series analysis, classification, clustering, …) and graphical techniques, and is highly extensible. One of R’s strengths is the ease with which well-designed publication-quality plots can be produced, including mathematical symbols and formulae where needed.

Linear models, their variants, and extensions are among the most useful and widely used statistical tools for social research. This course aims to provide an accessible, in-depth, modern treatment of *regression analysis*, *linear models*, *generalized linear models*, and closely related methods.

# 4. Text Books

- Wickham, H. (2019).
*Advanced R*(2 ed.). Boca Baton, UK: CRC Press. - Wickham, H., & Grolemund, G. (2016).
*R for Data Science: Import, Tidy, Transform, Visualize, and Model Data*. Sebastopol, CA: O’Reilly Media. **Fox, J. (2016).***Applied Regression Analysis and Generalized Linear Models*(3 ed.). Thousand Oaks, CA: SAGE.

# 5. Syllabus and Lecture Notes

- Part 0: Introduction
- Part I: Data craft
- Part II: Linear models and least squares
- Part III: Linear-model diagnostics
- Unusual and influential data

- Non-Normality, Nonconstant Error Variance, and Nonlinearity

- Collinearity and Its Purported Remedies

- Part IV: Generalized linear models
- Logit and Probit Models for Categorical Response Variables

- Generalized Linear Models

- Part V. Extending Linear and Generalized Linear Models
- Time-Series Regression and Generalized Least Squares

- Nonlinear Regression

- Nonparametric Regression

- Bootstrapping Regression Models

- Part VI: Mixed-Effects Models
- Linear Mixed-Effects Models

- Generalized Linear and Nonlinear Mixed-Effects Models

# 6. Final Examination

To successfully complete the examination, your computer should have already installed the

*R*software and at least two extra R packages:*rmarkdown*and*car*.Download the file from the following link: Final_Exam. The link is available from

**2020-12-23, 0900**to**2020-12-24, 2359**.Unzip and rename the

`Rmd`

file into the following formatin Pinyin, such as`SurnameGivenname_Student Number.Rmd`

.`ZhangSan_20170708.Rmd`

Open the renamed

file with`.Rmd`

and change the`R`

region in the front matter of the`Name-Number`

file to your own name in Chinese characters and your student number, such as`Rmd`

.`张三 - 20181030`

```
---
title: "期末考试试卷"
subtitle: "R语言与数据可视化和统计"
author: "张三 - 20181030" # <- Your name and student number
lastmod: "2020-12-23"
date: '2019-01-04'
output:
html_document
--- # <- You can write any text after this
```

- A
*Rmd*document can include both normal texts and legal R code. The*R*code should be enclosed by````{r} XXX ````

, i.e., the XXX region; and the normal texts that do not include the R code should be out of those regions. For example,

```
a. You can add any text here.
```{r}
# You can add comments here
str(Titanic) # <- This should be eligible R code.
```
b. You can also add any text here.
```

- After finishing all your answers, use R to render the Rmd file into a html file with the function:

```
install.packages("rmarkdown", dependencies = TRUE)
rmarkdown::render(
"directory/to/your/file/ZhangSan_20181030.rmd",
output_format = "html_document")
```

- Send both the finished
*.Rmd*file, such as*ZhangSan_20181030.Rmd*and the knitted*.html*file， such as*ZhangSan_20181030.html*to the following email address:`zhanlikan@blcu.edu.cn`

before**2020-12-24, 2359**.