project draft adout used car
#read data
data=read.csv(file=file.choose(),header = T,na.strings = c("NA",""))
#rename data
names(data)=c("Vehicle.brand","brand","location","style","type","emission","gear","model","time","kilometres","price","original.price","hedge.ratio","group1","group2")
#Check the number of cars sold
table(data$Vehicle.brand)
DS5 GMC赛威
1 2
Jeep大切诺基 Jeep牧马人
6 4
Jeep指南者 Jeep自由客
4 1
MG6 MINI
3 16
MINICabrio MINIClubman
2 4
MINICountryman MINICoupe
4 3
MINIMini SmartFortwo
1 2
SmartFortwo Cabrio SmartFortwo Coupe
2 3
奥迪A3 奥迪A4
5 5
奥迪A4L 奥迪A5
17 1
奥迪A6L 奥迪A7
49 2
奥迪A8L 奥迪Q3
7 9
奥迪Q5 奥迪Q7
16 17
奥迪RS5 奥迪TT
1 7
宝骏乐驰 宝马1系
2 10
宝马3系 宝马4系
45 1
宝马5系 宝马6系
61 2
宝马7系 宝马X1
4 13
宝马X3 宝马X4
6 1
宝马X5 宝马X6
10 3
宝马Z4 保时捷Macan
5 1
保时捷博克斯特 保时捷卡曼
2 2
保时捷卡宴 保时捷帕纳美拉
4 3
北京E系列 奔驰A级
7 3
奔驰A级 AMG 奔驰B级
2 1
奔驰CLA级 奔驰CLK级
2 1
奔驰C级 奔驰E级
31 15
奔驰GLA级 奔驰GLK级
1 16
奔驰M级 奔驰R级
6 4
奔驰SLK级 奔驰S级
4 14
奔驰唯雅诺 奔腾X80
2 1
本田CR-V 本田CR-Z
5 2
本田奥德赛 本田锋范
2 5
本田歌诗图 本田杰德
6 4
本田思铂睿 本田思域
6 5
本田雅阁 比亚迪F0
15 2
比亚迪F3 比亚迪F6
7 2
比亚迪G3R 比亚迪L3
1 2
比亚迪S6 比亚迪S7
11 7
比亚迪思锐 标致2008
1 3
标致207-两厢 标致207-三厢
3 1
标致3008 标致307-两厢
10 2
标致307-三厢 标致308
2 3
标致408 标致508
16 11
别克GL8 别克昂科拉
23 5
别克昂科威 别克君威
1 21
别克君威GS 别克君越
3 20
别克凯越 别克林荫大道
5 1
别克威朗 别克英朗
1 8
传祺GS4 大通G10
1 1
大众CC 大众Polo
21 17
大众up! 大众宝来
2 24
大众高尔夫 大众辉腾
49 2
大众甲壳虫 大众捷达
12 10
大众朗行 大众朗逸
1 18
大众朗逸2011款 大众迈特威
1 2
大众迈腾 大众帕萨特
61 22
大众桑塔纳 大众尚酷
11 8
大众速腾 大众途安
51 17
大众途观 大众途锐
27 5
大众夏朗 道奇酷威
4 5
东风风度MX6 东风风度帅客
1 2
东风风行景逸 东风风行菱智
1 10
东风风行菱智M3 东南DX7
6 2
东南V3菱悦 菲亚特菲翔
11 1
菲亚特致悦 丰田FJ酷路泽
2 2
丰田RAV4 丰田汉兰达
10 12
丰田花冠 丰田皇冠
1 7
丰田卡罗拉 丰田凯美瑞
18 10
丰田兰德酷路泽 丰田普拉多
1 1
丰田锐志 丰田塞纳
4 2
丰田威驰 丰田雅力士
3 5
福特福克斯 福特嘉年华
54 3
福特蒙迪欧 福特猛禽
25 5
福特全顺 福特锐界
6 5
福特探险者 福特翼搏
4 5
福特翼虎 福田风景
1 3
哈弗H2 哈弗H3
2 2
哈弗H6 海马福美来二代
3 1
华普海景 华泰宝利格
2 1
华泰圣达菲 吉利GX7
2 2
吉利博瑞 吉利帝豪EC7-RV
1 2
吉利帝豪EC8 吉利英伦SC7
2 1
吉利自由舰 江淮和悦
2 1
江淮和悦IEV4 江淮和悦RS
3 2
江淮瑞风S5 江淮瑞风彩色之旅
2 2
江淮瑞风穿梭 江淮瑞风祥和
2 1
捷豹F-Type 捷豹XF
2 2
捷豹XJ 金杯大海狮L
12 1
金杯阁瑞斯 金杯海狮
3 5
金杯小海狮X30 开瑞K50
2 1
凯迪拉克ATS-L 凯迪拉克SRX
1 10
凯迪拉克XTS 凯迪拉克凯雷德 油电混合
2 1
凯迪拉克凯雷德油电混合 凯迪拉克赛威SLS
1 1
克莱斯勒300C 雷克萨斯ES
2 4
雷克萨斯GS 雷克萨斯IS
5 3
雷克萨斯NX 雷克萨斯RX
1 1
雷诺科雷傲 铃木奥拓
3 5
铃木北斗星 铃木北斗星E+
3 3
铃木吉姆尼 铃木羚羊
4 1
铃木启悦 铃木天语SX4-两厢
2 6
铃木雨燕 陆风X5
4 1
陆风X8 路虎发现4
2 4
路虎揽胜 路虎揽胜极光
8 15
路虎揽胜极光Coupe 路虎揽胜运动版
1 5
路虎神行者2代 马自达2
5 3
马自达3 马自达5
7 2
马自达6 马自达8
19 2
马自达睿翼 纳智捷大7
8 1
纳智捷大7MPV 奇瑞A3-两厢
2 2
奇瑞A5 奇瑞E3
2 2
奇瑞E5 奇瑞QQ3
2 16
奇瑞QQme 奇瑞风云2-两厢
1 2
奇瑞旗云 奇瑞瑞虎
4 6
奇瑞瑞虎5 启辰晨风
3 1
起亚K2-三厢 起亚K3
3 2
起亚K5 起亚福瑞迪
5 1
起亚锐欧 起亚赛拉图
2 2
起亚狮跑 起亚索兰托
4 2
起亚威客 起亚秀尔
1 2
起亚智跑 日产NV200
5 2
日产骊威 日产玛驰
2 3
日产帕拉丁 日产奇骏
1 14
日产骐达 日产天籁
7 13
日产逍客 日产轩逸
17 2
日产颐达 荣威350S
3 2
荣威360 荣威550
1 10
荣威750E 荣威750S
1 1
荣威W5 三菱戈蓝
1 1
三菱劲炫 三菱劲炫2011款
1 1
三菱君阁 三菱欧蓝德
1 2
三菱欧蓝德EX劲界 三菱帕杰罗
2 2
三菱翼神 绅宝
1 3
绅宝D20-两厢 绅宝D20-三厢
2 2
绅宝D50 双龙爱腾
4 1
双龙柯兰多 斯巴鲁傲虎
1 3
斯巴鲁力狮 斯巴鲁森林人
2 7
斯柯达昊锐 斯柯达晶锐
14 10
斯柯达明锐 斯柯达昕动
12 1
斯柯达野帝 威麟X5
2 1
威旺306 威旺M20
2 2
沃尔沃C30 沃尔沃S40
1 5
沃尔沃S60 沃尔沃S60L
2 2
沃尔沃S80L 沃尔沃XC60
4 5
沃尔沃XC90 五菱宏光
2 3
五菱宏光S 五菱荣光
5 2
现代ix35 现代名图
15 3
现代名驭 现代瑞纳-三厢
2 2
现代索纳塔 现代途胜
16 11
现代维拉克斯 现代新胜达
3 25
现代雅绅特 现代伊兰特
3 19
现代伊兰特-三厢 雪佛兰爱唯欧-三厢
5 2
雪佛兰景程 雪佛兰科鲁兹
5 20
雪佛兰科迈罗 雪佛兰科帕奇
1 6
雪佛兰乐风 雪佛兰迈锐宝
7 8
雪佛兰赛欧-三厢 雪铁龙C4
5 2
雪铁龙C5 雪铁龙爱丽舍
20 5
雪铁龙毕加索 雪铁龙凯旋
1 2
雪铁龙世嘉 一汽骏派D60
20 1
英菲尼迪G25-三厢 英菲尼迪JX35
6 1
英菲尼迪Q50 长安CS35
1 4
长安CS75 长安CX20
1 3
长安奔奔 长安商用金牛星
2 1
长安商用欧诺 长安商用星光4500
7 2
长安商用长安之星2 长安商用长安之星Ⅱ代
2 1
长安逸动 长安悦翔-三厢
4 1
长安悦翔V3 长城C30
3 2
长城C50 长城M2
1 3
长城M4 中华H530
5 1
中华骏捷FRV 中华尊驰
3 2
data=data[,-2]
###clean data###
#In addition to the top ten brands, change to other
brand_10=sort(table(data$Vehicle.brand),decreasing = T)
brand_10[1:10]
宝马5系 大众迈腾 福特福克斯 大众速腾 奥迪A6L 大众高尔夫
61 61 54 51 49 49
宝马3系 奔驰C级 大众途观 福特蒙迪欧
45 31 27 25
attach(data)
=which(Vehicle.brand!="宝马5系"& Vehicle.brand!="大众迈腾"& Vehicle.brand!="福特福克斯"
b& Vehicle.brand!="大众速腾"& Vehicle.brand!="奥迪A6L"& Vehicle.brand!="大众高尔夫"
& Vehicle.brand!="宝马3系"& Vehicle.brand!="奔驰C级"& Vehicle.brand!="大众途观"
& Vehicle.brand!="福特蒙迪欧")
detach(data)
1]=as.character(data[,1])
data[,1]="others"
data[b,1]=as.factor(data[,1])
data[,
#location:
table(data$location)
外国 中国
1783 251
#style锛<9a>NAtable(data$style)
2005款 2006款 2007款 2008款 2009款 2010款 2011款 2012款 2013款 2014款
1 8 35 111 197 262 276 364 371 257
2015款 2016款
130 22
levels(data$style)
NULL
#The model can be determined according to the brand and style of the vehicle, so delete the data
data=data[,-4]
data=data[,-6]
data=na.omit(data)
head(data)
Vehicle.brand location style emission gear time kilometres
1 others 外国 2007款 6L 自动 2012/12/1 1.1
2 others 外国 2010款 6L 无级 2011/5/1 5.8
3 others 外国 2010款 6L 无级 2011/5/1 5.8
4 others 外国 2011款 6.2L 自动 2014/11/1 2.9
5 others 外国 2011款 6.2L 自动 2014/11/1 2.9
6 others 外国 2011款 6.2L 自动 2013/7/1 5.0
price original.price hedge.ratio group1 group2
1 59.5 132.4 0.45 小于10万 高级轿车
2 60.0 151.7 0.40 小于10万 高级轿车
3 60.0 151.7 0.40 小于10万 高级轿车
4 48.0 71.4 0.67 小于10万 高级轿车
5 48.0 71.4 0.67 小于10万 高级轿车
6 41.5 71.4 0.58 小于10万 高级轿车
# price of car
library(dplyr)
car_style <- group_by(data, style) %>%
summarise(n=n(), mean(price),median(price),sd(price),
mean_hedge.ratio=mean(hedge.ratio),sd_hedge.ratio=sd(hedge.ratio),
na.rm = TRUE) %>%
mutate(freq = n / sum(n))
car_style
# A tibble: 12 x 9
style n `mean(price)` `median(price)` `sd(price)`
<chr> <int> <dbl> <dbl> <dbl>
1 2005款 1 38.5 38.5 NA
2 2006款 8 9.45 10.8 4.39
3 2007款 35 11.1 7.3 11.5
4 2008款 111 6.59 5.1 3.81
5 2009款 197 7.79 6.5 5.05
6 2010款 262 13.7 10.5 14.1
7 2011款 276 14.9 11 12.2
8 2012款 362 16.9 11.1 16.1
9 2013款 370 20.9 17.5 13.8
10 2014款 253 27.6 18.5 22.1
11 2015款 128 24.6 16.5 27.6
12 2016款 22 25.7 19 19.4
# ... with 4 more variables: mean_hedge.ratio <dbl>,
# sd_hedge.ratio <dbl>, na.rm <lgl>, freq <dbl>
#Visualize the price
library(ggplot2)
ggplot(data, aes(price, fill =style)) + geom_histogram(color="black")+
labs(title = "price") +
theme(axis.text=element_text(size=6)) +
facet_wrap(vars(style), scales = "free")
#Hedging Rate Density Plot
ggplot(data,aes(x=hedge.ratio))+geom_density(fill="pink")+
labs(title="Hedging Rate Density Plot",x="Hedging Rate", y="Density") +
theme_bw()
#Value retention rate of different styles & location of cars
ggplot(data, aes(x=style, y=hedge.ratio,color = style)) + geom_jitter(width = .25, alpha = .3)+
geom_violin(fill = "gray80", size = .5, alpha = .5)+
stat_summary(fun = "mean",geom="point")+
labs(title="Value retention rate of different cars",x="style", y="hedging rate") +
theme(axis.text=element_text(size=4),)+
facet_wrap(vars(location), scales = "free")
#Uncertainty of hedging rate
ggplot(car_style,aes(style,mean_hedge.ratio,color=style))+
geom_col(fill = "gray60", size = .8, alpha = .6)+
geom_errorbar(aes(style,
ymin=mean_hedge.ratio-sd_hedge.ratio,
ymax=mean_hedge.ratio+sd_hedge.ratio))+
labs(title="Uncertainty of hedging rate",x="style", y="hedge.ratio")+
theme(axis.text=element_text(size=6))
- What is missing from your final project? |
Nothing. |
- What do you hope to accomplish between now and submission time? |
Maybe more visualization and analysis. |
Text and figures are licensed under Creative Commons Attribution CC BY-NC 4.0. The figures that have been reused from other sources don't fall under this license and can be recognized by a note in their caption: "Figure from ...".
For attribution, please cite this work as
Xiaotong (2022, May 11). Data Analytics and Computational Social Science: hw6_xiaotonglin. Retrieved from https://github.com/DACSS/dacss_course_website/posts/httprpubscomtoni901236/
BibTeX citation
@misc{xiaotong2022hw6_xiaotonglin, author = {Xiaotong, }, title = {Data Analytics and Computational Social Science: hw6_xiaotonglin}, url = {https://github.com/DACSS/dacss_course_website/posts/httprpubscomtoni901236/}, year = {2022} }