無標(biāo)題文章

[if !supportLists]1.?????[endif]請將數(shù)據(jù)hw1_a和hw1_b分別讀入R,查看數(shù)據(jù)并指出各個變量的形式,最小值,最大值,中值,均值,標(biāo)準(zhǔn)差。

[if !supportLists]2.?????[endif]結(jié)合上課我們所學(xué)的幾種數(shù)據(jù)join 的形式,將兩個數(shù)據(jù)集進(jìn)行合并。對于每種數(shù)據(jù)合并的方式,請說明key, 并且報告合并后的數(shù)據(jù)樣本總行數(shù)。

[if !supportLists]3.?????[endif]請篩選出hw1_a 中收入大于4000的樣本,并將此樣本和hw1_b 中Is_Default=1的樣本合并,你可以使用inner join的方式。這一問中你可以用pipe的書寫形式。

[if !supportLists]4.?????[endif]在第2問的基礎(chǔ)上, 請給出Income對Years_at_Employer的散點圖,你發(fā)現(xiàn)了哪些趨勢和現(xiàn)象?

[if !supportLists]5.?????[endif]在第4問的基礎(chǔ)上 按照Is_Default 增加一個維度,請展示兩變量在不同違約狀態(tài)的散點圖。請使用明暗程度作為區(qū)分方式

[if !supportLists]6.?????[endif]對于第5問,請使用形狀作為另外一種區(qū)分方式。

[if !supportLists]7.?????[endif]請找出各個列的缺失值,并刪除相應(yīng)的行。請報告每一變量的缺失值個數(shù),以及所有缺失值總數(shù)。

[if !supportLists]8.?????[endif]找出Income中的極端值并濾掉對應(yīng)行的數(shù)據(jù)

[if !supportLists]9.?????[endif]將Income對數(shù)化,并畫出直方圖和density curve.

[if !supportLists]10.??[endif]以Income作為因變量,Years at Employer作為自變量,進(jìn)行OLS回歸,寫出回歸的方程,并指出自變量系數(shù)是否在某一顯著性水平上顯著。同時,解釋你的結(jié)果(這一問你自己發(fā)揮可以找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)

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容