---
title: "Voorwaarden lineaire regressie"
author: "Hans Van Eetvelde"
date: "6-11-2020"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

# Libraries inlezen

```{r}
library(dplyr)
library(ggplot2)
```

# Voorwaarden voldaan

```{r}
set.seed(6112020)
x<-rnorm(100)
beta_0<-9
beta_1<-3
epsilon<-rnorm(100, mean=0, sd=1) #residuen
y<-beta_0+beta_1*x+epsilon
data1<-data.frame(x,y)
plot1<-ggplot(data1, aes(x=x, y=y))+
  geom_point()+
  stat_smooth(method='lm')
plot1
model<-lm(y~x)
plot(model, which=1:3)
```  


# Voorwaarden niet voldaan: geen lineair verband

```{r}
set.seed(6112020)
x<-rnorm(100)
epsilon<-rnorm(100, mean=0, sd=1)
beta_0<-9
beta_1<-3
y<-beta_0+beta_1*x^2+epsilon #kwadratisch verband
data1<-data.frame(x,y)
plot1<-ggplot(data1, aes(x=x, y=y))+
  geom_point()+
  stat_smooth(method='lm')
plot1
model<-lm(y~x)
plot(model, which=1:3)
```  
# Voorwaarden niet voldaan: geen constante variantie

```{r}
set.seed(6112020)
x<-rnorm(100)
epsilon<-rnorm(100, mean=0, sd=x-min(x)+0.1) #geen constante variantie
beta_0<-9
beta_1<-3
y<-beta_0+beta_1*x+epsilon 
data1<-data.frame(x,y)
plot1<-ggplot(data1, aes(x=x, y=y))+
  geom_point()+
  stat_smooth(method='lm')
plot1
model<-lm(y~x)
plot(model, which=1:3)
```  

# Geen normale verdeling

```{r}
set.seed(6112020)
x<-rnorm(100)
epsilon<-rchisq(100, df=1) #geen normale verdeling
beta_0<-9
beta_1<-3
y<-beta_0+beta_1*x+epsilon 
data1<-data.frame(x,y)
plot1<-ggplot(data1, aes(x=x, y=y))+
  geom_point()+
  stat_smooth(method='lm')
plot1
model<-lm(y~x)
plot(model, which=1:3)
```  

```{r}
set.seed(6112020)
x<-rnorm(100)
epsilon<-runif(100, -2,2) #geen normale verdeling
beta_0<-9
beta_1<-3
y<-beta_0+beta_1*x+epsilon 
data1<-data.frame(x,y)
plot1<-ggplot(data1, aes(x=x, y=y))+
  geom_point()+
  stat_smooth(method='lm')
plot1
model<-lm(y~x)
summary(model)
plot(model, which=1:3)
```  




