R語言數(shù)據(jù)分析回歸研究案例報告附代碼數(shù)據(jù)_第1頁
R語言數(shù)據(jù)分析回歸研究案例報告附代碼數(shù)據(jù)_第2頁
R語言數(shù)據(jù)分析回歸研究案例報告附代碼數(shù)據(jù)_第3頁
R語言數(shù)據(jù)分析回歸研究案例報告附代碼數(shù)據(jù)_第4頁
R語言數(shù)據(jù)分析回歸研究案例報告附代碼數(shù)據(jù)_第5頁
已閱讀5頁,還剩4頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

R語言數(shù)據(jù)分析回歸研究案例:移民政策偏好是否有準確的刻板印象?options(digits=2)library(pacman)p_load(kirkegaard,dplyr,readr,googlesheets,lavaan,polycor,e1071,rms)#adhocfuncInf_to_NA=function(x){x[is.infinite(x)]=NAx}數(shù)據(jù)#loaddatasilence({kb16=read_rds("data/KirkegaardandBjerrek?r2016data.rds").kb16_aggr=read_rds("data/KirkegaardandBjerrek?r2016dataaggr.rds")%>%dk_fiscalrownames_to_column("ISO")dk_fiscal=read_csv("data/denmark.csv"#mergedk_fiscal=full_join(dk_fiscal,kb16_aggr,by="ISO")%>%mutate(dk_fiscal=dnk_net_fiscal_contribution,dk_benefits_use=Denmark.Social_benefits_30_39,Muslim_frac=IslamPewResearch2010)%>%arrange(ISO)#subsetdk_fiscal_sub=dk_fiscal%>%ilter(!is.na(dk_fiscal))#newdatags=gs_url("https://docs.google.cOm/spreadsheets/d/1jsaXush5hD2rlyhzA0VaB8LR1eRb1h9mJOphTwCgeiU/edit#gid=1277242299")d=gs_read(gs)})重命名,重新編碼,重組#controlscontrol_items=str_detect(names(d),"V?lg")%>%which()#subset,rename,scored_controls=d[controljtems]d_controls[[5]]=d_controls[[5]]%in%60:70d_controls%<>%corejtems(c("Sammeantalindvandrere","F?rreindvandrere","Negativt","Positivt",T))names(d_controls)="control_"+1:5d_controls%<>%nap_df(as.logical)#prefspref_items=str_detect(names(d),"detsammeantalindvandrere")%>%which()%>%setdiff(control_items)econ_items=str_detect(names(d),"indvandrergrupperiDanmarkbidragertilf?lleskassen")%>%which()%>%setdiff(control_items)#subsetd_prefs=d[pref_items]d_econ=d[econ_items]#sortvariablesbynamefunctiondf_sort_vars=function(x){x[sort(names(x))]}#rename,andtoISO-3names(d_prefs)=str_match(names(d_prefs),"A[A:]+")%>%as.vector()%>%pu_translate()#Noexactmatch:DettidligereJugoslavien#Bestfuzzymatchfound:DettidligereJugoslavien->Jugoslavienwithdistance14.00names(d_econ)=str_match(names(d_econ),"八[八:]+”)%>%as.vector()%>%pu_translate()#Noexactmatch:DettidligereJugoslavien#Bestfuzzymatchfound:DettidligereJugoslavien->Jugoslavienwithdistance14.00TOC\o"1-5"\h\zd_prefs%<>%if_sort_vars()d_econ%<>%df_sort_vars()#partyagreementsparty_items=str_detect(names(d),"medhvertpolitiskeparti")%>%which()%>%setdiff(control_items)d_parties=d[party_items]names(d_parties)=str_match(names(d_parties),"A[A:]+")novarianceinestimatesd_controls$control_no_var=map_lgl(1:nrow(d),function(x){d[x,econ_items]%>%unlist%>%ll_the_same()%>%not()})

#QCpolycor::hetcor(d_controls%>%s.data.frame##())##Two-StepEstimates#QCpolycor::hetcor(d_controls%>%s.data.frame##())##Two-StepEstimates####Correlations/TypeofCorrelation:##control5control1control2control3control4##control_1

Polychoric1PolychoricPolychoricPolychoric#control_20.517Polychoric#control_30.621olychoric#control_40.693lychoric#control_50.5741##control_no_var0.2260.2151PolychoricPolychoric0.7091PolychoricP0.7590.911Po0.4420.5990.6740.4170.5470.604#control_no_var#control_1Polychoric#control_2Polychoric#control_3Polychoric#control_4Polychoric#control_5Polychoric#control_no_var1###StandardErrors:#control_1control_2control_3control_4control_5#control_1#control_20.0609#control_30.05040.0422#control_40.04540.03830.0187#control_50.05240.05870.04620.0423#control_no_var0.08460.07220.06010.05680.0751###n=850QC_score=rowSums(d_controls)table2(QC_score)GroupCountPercentTOC\o"1-5"\h\z<chr><dbl><dbl>647656.00517921.06607.06546.35465.411273.18080.94NA00.008rows#keeporigsorigs=list(d_econ=d_econ,d_prefs=d_prefs,d=d)#subsetd_econ=d_econ[QC_score==6,]d_prefs=d_prefs[QC_score==6,]d=d[QC_score==6,]#recoded_econ_num=d_econ%>%nap_df(~plyr::mapvalues(.,from=c("Megetnegativt","Negativt","Lidtnegativt","Neutralt","Lidtpositivt","Positivt","Megetpositivt"),to=1:7,warn_missing=F)%>%as.numeric())d_prefs_num=d_prefs%>%nap_df(~plyr::mapvalues(.,from=c("Ingenindvandrere","F?rreindvandrere","Sammeantalindvandrere","Flereindvandrere"),to=c(1,1,-1,-1),warn_missing=F)%>%as.numeric())d_prefs_num_alt=d_prefs%>%nap_df(~plyr::mapvalues(.,from=c("Ingenindvandrere","F?rreindvandrere","Sammeantalindvandrere","Flereindvandrere"),to=1:4,warn_missing=F)%>%as.numeric())#basicd$gender=d$'URLVariable:gender'%>%)lyr::mapvalues(c(1,2),c("Male","Female"))%>%factor(levels="Male","Female")d$age=d$'URLVariable:yob'%>%ubtract(2017)%>%abs()#auxd$Muslims_are_treated_well=d[[90]]d$DK_admit_only_net_positive_immigrants=d[[91]]d$nonwesterns_are_net_positive=d[[92]]d$party_vote=d[[89]]#partiesd_parties=d[str_detect(names(d),"hvor0heltuenig,og100erheltenig")%>%which()%>%setdiff(control_items)]names(d_parties)=str_match(names(d_parties),"[A:]+")%>%as.vector()%>%str_replace_all("","_")d=cbind(d,d_parties)對Kirkegaard&Bjerrek?r2016的再分析確定用于本研究的32個國家的子集的總體準確性。#correlationbetweenoutcomes

"dkfiscal"caseGG_scatter(dk_fiscal,"dk_benefits_use"_names="Names")"dkfiscal"caser=070[CI95:0,550.60](orangeIme}Kuwaitn=70S&i^alSSerbia&iJontenegro.XMyanmarF&rrtWif優(yōu)igOAUVUkAfghanisl^LP--4020aw笆4ju£xpiJor^ian/1*****BosjiiasndHarze^cvinaAlqlija昆sb?高修島證RepTu而豳a?.SrlLanka

Cijfthfltvaikia

terdell.電工'j口EgyptAfabRep.TanzaniaEthiopiaUgandaRbs&an囂Mgrt電siaPaktslana盤K01PcJSnd?BulgariaRomaniaQhSrtfi.Nigeria1Q2。304。meanestimaleGG_scatter(dk_fiscal_sub,"mean_estimate","dk_benefits_use",case_names="Name

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論