---
title: "PSYC 193R: Lecture 13"
output: html_notebook
---

# Lecture 13: Brain size and Intelligence

# Correlation, t-test, & Regression
Download the data file: 
https://psyc193r.ucsd.edu/data/psyc193r_intelligence_data.csv

Load the data
```{r}
# load data
setwd(NA)
intelligenceData = read.csv("file_path")

# or... load data from url 
intelligenceData = read.csv("url")

# check data structure

```

Factorize / as.numeric variables
```{r}
# Factorize

# as.numeric

```

Check outliers
```{r}
# histograms
# the iv
hist(NA)

# the dv
hist(NA)

#scatterplot
with(intelligenceData, plot(NA, NA))
```

Correlation coefficients
```{r}
# correlation coefficient
with(intelligenceData, cor(NA, NA))

# variance explained by the model

```

Build a linear model
```{r}
# build a model
iq.lm = lm( NA ~ NA, data = intelligenceData)

# read out the summary of the model
summary(iq.lm)
```

Prediction
```{r}
# generate a new data frame for the iv
newScore = data.frame(brainVol = 1250)

# use predict()
predict(NA , newScore, interval = "prediction") # put in the lm model
```

Visualization
```{r}
# ggplot
library(ggplot2)
ggplot(data = NA , aes(x=NA, y=NA)) +
  geom_point(shape=1) +    # Use hollow circles
  geom_smooth(method=lm)   # Add linear regression line 
                           #  (by default includes 95% confidence region)
```

Residual plot
```{r}
# calculate the predicted values given the iv
iq.res = resid( NA ) # put in the lm model

# plot the residuals
plot( NA, NA, main = "Residual Plot") # first cell: the iv; second cell: the predicted values
```
