无标题文章

[if !supportLists]1.     [endif]请将数据hw1_a和hw1_b分别读入R,查看数据并指出各个变量的形式,最小值,最大值,中值,均值,标准差。

[if !supportLists]2.     [endif]结合上课我们所学的几种数据join 的形式,将两个数据集进行合并。对于每种数据合并的方式,请说明key, 并且报告合并后的数据样本总行数。

[if !supportLists]3.     [endif]请筛选出hw1_a 中收入大于4000的样本,并将此样本和hw1_b 中Is_Default=1的样本合并,你可以使用inner join的方式。这一问中你可以用pipe的书写形式。

[if !supportLists]4.     [endif]在第2问的基础上, 请给出Income对Years_at_Employer的散点图,你发现了哪些趋势和现象?

[if !supportLists]5.     [endif]在第4问的基础上 按照Is_Default 增加一个维度,请展示两变量在不同违约状态的散点图。请使用明暗程度作为区分方式

[if !supportLists]6.     [endif]对于第5问,请使用形状作为另外一种区分方式。

[if !supportLists]7.     [endif]请找出各个列的缺失值,并删除相应的行。请报告每一变量的缺失值个数,以及所有缺失值总数。

[if !supportLists]8.     [endif]找出Income中的极端值并滤掉对应行的数据

[if !supportLists]9.     [endif]将Income对数化,并画出直方图和density curve.

[if !supportLists]10.  [endif]以Income作为因变量,Years at Employer作为自变量,进行OLS回归,写出回归的方程,并指出自变量系数是否在某一显著性水平上显著。同时,解释你的结果(这一问你自己发挥可以找code解决)。

#######   1  ######

library(readxl)

hw1_a<-read_excel("hw1_a.xlsx",col_types=c("numeric","numeric", "numeric",

                                             "numeric", "numeric"))

hw1_b<-read_excel("hw1_b.xlsx")


str(hw1_a)

str(hw1_b)


summary(hw1_a)

summary(hw1_b)


sd(hw1_a$Income)


library(psych)

describe(hw1_a)

describe(hw1_b)



########    2    #######

library(tidyverse)

hw1_a %>%

  inner_join(hw1_b,by="ID")

hw1_a %>%

  left_join(hw1_b,by="ID")

hw1_a %>%

  right_join(hw1_b,by="ID")

hw1_a %>%

  full_join(hw1_b,by="ID")


inner_join<-inner_join(hw1_a,hw1_b,by="ID")

(nrow(inner_join))


full_join<-full_join(hw1_a,hw1_b,by="ID")

(nrow(full_join))


#########    3    ########

hw1_a1=filter(hw1_a,Income>40000)

hw1_b1=filter(hw1_b,Is_Default==1)


inner_join1<-inner_join(hw1_a1,hw1_b1,by="ID")



#########   4    #########

ggplot(data=inner_join)+

  geom_point(mapping =aes(x=Years_at_Employer,y= Income))



########    5     ############

ggplot(data=inner_join)+

  geom_point(mapping =aes(x=Years_at_Employer,y= Income,alpha=Is_Default))


ggplot(data=inner_join)+

  geom_point(mapping =aes(x=Years_at_Employer,y= Income,

                          alpha=factor(Is_Default)))



########    6     ##########

ggplot(data=inner_join)+

  geom_point(mapping =aes(x=Years_at_Employer,y= Income,

                          shape=factor(Is_Default)))     



########    7     #########

sum(is.na(full_join[2]))

sum(is.na(full_join[3]))

sum(is.na(full_join[4]))

sum(is.na(full_join[5]))

sum(is.na(full_join[6]))

sum(is.na(full_join[7]))

sum(is.na(full_join[8]))

sum(is.na(full_join))


full_join1=filter(full_join,!is.na(full_join[2]))

full_join1=filter(full_join1,!is.na(full_join1[3]))

full_join1=filter(full_join1,!is.na(full_join1[4]))

full_join1=filter(full_join1,!is.na(full_join1[5]))

full_join1=filter(full_join1,!is.na(full_join1[6]))

full_join1=filter(full_join1,!is.na(full_join1[7]))

full_join1=filter(full_join1,!is.na(full_join1[8]))

sum(is.na(full_join1))



########  8  #########

quantile(hw1_a$Income,c(0.025,0.975))

hw1_a2=filter(hw1_a,Income>14168.81&Income<173030.92)



#######   9  #########

inc<-hw1_a$Income

lninc<-log(inc)


hist(lninc,prob=T)

lines(density(lninc),col="blue")



#######   10   #########

m1<-lm(Income~Years_at_Employer,data=hw1_a)

summary(m1)

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • https://jorryyang.gitee.io/rdata/ 第一次作业: 题目: 请下载hw1_a和hw1...
    2020MEM阅读 215评论 0 0
  • R数据科学### 20200919 8:30 raining#### shif+enter 换行 planes ...
    miki1823阅读 1,006评论 0 2
  • 请下载hw1_a和hw1_b两个excel数据文件,完成以下任务: 1.请将数据hw1_a和hw1_b分别读入R,...
    bellable阅读 648评论 0 1
  • # 11The impact of regulations on the supply and quality o...
    Ordinary阅读 358评论 0 1
  • # International Relations > # A House of Cards ## Section...
    Sheychu阅读 658评论 0 2