── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
✖ dplyr::select() masks MASS::select()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(corrplot)
corrplot 0.92 loaded
library(AER)
Loading required package: car
Loading required package: carData
Attaching package: 'car'
The following object is masked from 'package:purrr':
some
The following object is masked from 'package:dplyr':
recode
Loading required package: lmtest
Loading required package: zoo
Attaching package: 'zoo'
The following objects are masked from 'package:base':
as.Date, as.Date.numeric
Loading required package: sandwich
Loading required package: survival
library(lmtest)library(gplots)
Attaching package: 'gplots'
The following object is masked from 'package:stats':
lowess
library(corrgram)
Tổng quan dữ liệu Boston
data("Boston")dim(Boston)
[1] 506 14
attach(Boston)?Boston
starting httpd help server ... done
Dữ liệu Boston
Biến
Định nghĩa
crim
tỷ lệ tội phạm/dân số
zn
tỷ lệ đất ở trên diện tích 25,000 feet vuông
indus
tỷ lệ diện tích ko có dịch vụ bán lẻ
chas
Có gần sông Charles không (1= gần; 0: không)
nox
nồng độ oxit nitric
rm
số phòng trung bình mỗi nhà
age
tỷ lệ số căn nhà ở được xây trước năm 1940
dis
khoảng cách trung bình (có trọng số) đến 5 trung tâm việc làm ở Boston
rad
biến chỉ số về khả năng tiếp cận với đường cao tốc
tax
thuế suất tài sản với giá trị 10,000 USD
ptratio
tỷ lệ học sinh/giáo viên
black
\(1000(Bk-0.63)^2\) với \(Bk\) là tỷ lệ người da đen
lstat
tỷ lệ người dân hạ lưu trên tổng dân số
medv
giá trị trung bình của nhà (tính theo 1000USD)
Thống kê mô tả
Giá trị các biến
library(psych)
Attaching package: 'psych'
The following object is masked from 'package:car':
logit
The following objects are masked from 'package:ggplot2':
%+%, alpha
par(mfrow =c(3,4))hist(medv,col='skyblue',main ="Histogram của giá nhà",xlab="Giá nhà",ylab="Tần suất")hist(crim,col='skyblue',main ="Histogram của tỷ lệ tội phạm",xlab="Tỷ lệ",ylab="Tần số")hist(zn,col='skyblue',main ="Histogram của tỷ lệ đất",xlab="Tỷ lệ",ylab="Tần số")hist(indus,col='skyblue',main ="Histogram của tỷ lệ diện tích khu công nghiệp",xlab="Tỷ lệ",ylab="Tần số")hist(nox,col='skyblue',main ="Histogram của nồng độ oxit nitric",xlab="Nồng độ",ylab="Tần số")hist(rm,col='skyblue',main ="Histogram của số phòng mỗi nhà",xlab="Số phòng",ylab="Tần số")hist(age,col='skyblue',main ="Histogram của tỷ lệ số căn nhà trước 1940",xlab="Tỷ lệ",ylab="Tần số")hist(dis,col='skyblue',main ="Histogram của khoảng cách đến trung tâm",xlab="Khoảng cách",ylab="Tần số")hist(tax,col='skyblue',main ="Histogram của thuế trên tài sản",xlab="Tỷ lệ",ylab="Tần số")hist(ptratio,col='skyblue',main ="Histogram của tỷ lệ học sinh trên giáo viên",xlab="Tỷ lệ",ylab="Tần số")hist(black,col='skyblue',main ="Histogram của tỷ lệ người da đen",xlab="Tỷ lệ",ylab="Tần số")hist(lstat,col='skyblue',main ="Histogram của tỷ lệ người dân hạ lưu",xlab="Tỷ lệ",ylab="Tần số")
Phân tích khám phá
Ma trận hệ số tương quan
#Chuyển biến medv thành log(medv) trong dữ liệu Bostondata.new=mutate(Boston,medv =log(medv))View(data.new)
H0: không có mối liên hệ giữa tiếp cận đường cao tốc và sông Charles
H1: có mối liên hệ giữa tiếp cận đường cao tốc và sông Charles
chisq.test(Boston$chas, Boston$rad)
Warning in chisq.test(Boston$chas, Boston$rad): Chi-squared approximation may
be incorrect
Pearson's Chi-squared test
data: Boston$chas and Boston$rad
X-squared = 13.898, df = 8, p-value = 0.08447
Giá trị p-value = 0.08447>0.05, do vậy, không thể bác bỏ giả thuyết H0 với mức ý nghĩa 5%, điều này cho thấy, chưa thể khẳng định có mối liên hệ giữa vị trí so với đường cao tốc và vị trí so với sông Charles
Welch Two Sample t-test
data: medv by chas
t = -3.1133, df = 36.876, p-value = 0.003567
alternative hypothesis: true difference in means between group 0 and group 1 is not equal to 0
95 percent confidence interval:
-10.476831 -2.215483
sample estimates:
mean in group 0 mean in group 1
22.09384 28.44000
p value < 0.05 -> có sự khác biệt có ý nghĩa thống kê giữa giá nhà gần sông và gần sông
Giá nhà từng khu vực
table(Boston$chas)
0 1
471 35
by(Boston$medv, chas, summary)
chas: 0
Min. 1st Qu. Median Mean 3rd Qu. Max.
5.00 16.60 20.90 22.09 24.80 50.00
------------------------------------------------------------
chas: 1
Min. 1st Qu. Median Mean 3rd Qu. Max.
13.40 21.10 23.30 28.44 33.15 50.00
So sánh giá nhà theo chỉ số tiếp cận đường cao tốc
Version: 1.39.3
Date: 2023-11-09
Author: Philip Leifeld (University of Essex)
Consider submitting praise using the praise or praise_interactive functions.
Please cite the JSS article in your publications -- see citation("texreg").
Attaching package: 'texreg'
The following object is masked from 'package:tidyr':
extract
library(stargazer)
Please cite as:
Hlavac, Marek (2022). stargazer: Well-Formatted Regression and Summary Statistics Tables.
R package version 5.2.3. https://CRAN.R-project.org/package=stargazer
stargazer(model1, model2, model3, model4, type ="text") #Compare to 4 models