-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinear bai 1.Rmd
69 lines (59 loc) · 1.54 KB
/
linear bai 1.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
---
title: "linear bai 1"
output: html_document
date: "2023-10-07"
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## R Markdown
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
#tai cac packages
```
install.packages("ggplot2")
install.packages("dplyr")
```
#tai cac libraries
```
library(ggplot2)
library(dplyr)
library(tidyr)
library(haven)
```
#doc file regression
```
df <- read_dta("Regression.dta")
View(df)
```
#phan tich tuong quan
```
cov(df$c38, df$wage, method ="pearson")
cor(df$c38, df$wage, method ="pearson")
```
#linear regression 1 sample
```
reg1 <- lm(wage ~ c38, data = df)
summary(reg1)
plot(df$c38, df$wage, xlab = "c38", ylab = "wage", col = "blue")
abline(reg1, col = "Red")
```
#phan tich hoi quy cho tung mau
```
dt = sort(sample(nrow(df),nrow(df)*.5))
df1 <- df[dt,]
df2 <- df[-dt,]
dim(df1)
dim(df2)
reg2 <- lm(df1$wage ~ df1$c38)
reg3 <- lm(df2$wage ~ df2$c38)
```
#danh gia cac tham so cho tung mo hinh hoi quy mau
```
summary(reg2)
summary(reg3)
plot(df$c38, df$wage, xlab = "c38", ylab = "wage", col = "blue")
abline(reg1, col = "Red")
abline(reg2, col = "Yellow")
abline(reg3, col = "Green")
```