Statistical Analysis-rxLinMod

Sample Code


사용할 데이터는 Revolution 폴더안의 Sample Data로, "mortDefaultSmall2009"라는 이름의 csv파일이다.  

데이터의 행 수는 총 10000개 이고, 'creditScore', 'houseAge', 'yearsEmploy', 'ccDebt', 'year', 'default' 로 총 6개의 변수(열)를 가지고 있다.  

현재 사용한 데이터는 2009년 데이터이지만, 실제는 2000년부터 2009년까지 10년간의 sample data가 있다.  

뒤에 데이터 합치기와 같은 부분에서 다른 연도의 데이터도 사용될 것이다.

1.Data Import하기


# (1-1)data의 위치지정 Revolution R을 다운할 시, 자동으로 생성되는 Sample

# data중 하나인 데이터로, sampleData폴더의 'mortDefaultSmall2009'
# csv파일을 사용

text_mort <- "C:/Revolution/R-Enterprise-6.1/R-2.14.2/library/RevoScaleR/SampleData/mortDefaultSmall2009.csv"


# (1-2)rxImport를 사용한 data import

data_mort <- rxImport(inData = text_mort, outFile = "mort1.xdf", overwrite = TRUE)

2.rxLinMod을 사용한 선형회귀분석(종속변수 1개)


# (1-3)rxLinMod를 사용한 선형회귀분석

mort_LinMod <- rxLinMod(creditScore ~ ccDebt + houseAge + yearsEmploy, data_mort)

다중회귀분석으로, 종속변수는 creditScore 하나이고, 독립변수는 ccDebt를 비롯하여, houseAge , yearsEmploy로 총 3개인 모형이라 할 수 있다.


summary(mort_LinMod)
## Call:
## rxLinMod(formula = creditScore ~ ccDebt + houseAge + yearsEmploy, 
##     data = data_mort)
## 
## Linear Regression Results for: creditScore ~ ccDebt + houseAge +
##     yearsEmploy
## File name: C:\Users\choi\Desktop\mort1.xdf
## Dependent variable(s): creditScore
## Total independent variables: 4 
## Number of valid observations: 10000
## Number of missing observations: 0 
##  
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  7.01e+02   2.30e+00  304.36  2.2e-16 ***
## ccDebt      -5.13e-04   2.56e-04   -2.01    0.044 *  
## houseAge     4.22e-02   6.71e-02    0.63    0.530    
## yearsEmploy  3.57e-01   2.51e-01    1.42    0.156    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 
## 
## Residual standard error: 50.8 on 9996 degrees of freedom
## Multiple R-squared: 0.000644 
## Adjusted R-squared: 0.000344 
## F-statistic: 2.15 on 3 and 9996 DF,  p-value: 0.0919 
## Condition number: 1.016

추정치와, 표준오차, t값, 유의확률까지 확인가능하다.

3.rxLinMod을 사용한 선형회귀분석(종속변수 2개)


# 종속변수를 2개

mort_LinMod2 <- rxLinMod(cbind(creditScore, yearsEmploy) ~ ccDebt + houseAge, 
    data_mort)

종속변수가 들어갈 자리에 cbind를 사용하여 두 개의 변수를 묶어주면, 2개 이상의 종속변수에 대한 모형이 가능하다.


summary(mort_LinMod2)
## Call:
## rxLinMod(formula = cbind(creditScore, yearsEmploy) ~ ccDebt + 
##     houseAge, data = data_mort)
## 
## Linear Regression Results for: creditScore ~ ccDebt + houseAge
## File name: C:\Users\choi\Desktop\mort1.xdf
## Dependent variable(s): creditScore, yearsEmploy
## Total independent variables: 3 
## Number of valid observations: 10000
## Number of missing observations: 0 
##  
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  7.02e+02   1.93e+00  364.29  2.2e-16 ***
## ccDebt      -5.12e-04   2.56e-04   -2.00    0.045 *  
## houseAge     4.24e-02   6.71e-02    0.63    0.528    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 
## 
## Residual standard error: 50.8 on 9997 degrees of freedom
## Multiple R-squared: 0.000443 
## Adjusted R-squared: 0.000243 
## F-statistic: 2.21 on 2 and 9997 DF,  p-value: 0.109 
## Condition number: 1.009 
## 
## :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
## 
## Call:
## rxLinMod(formula = cbind(creditScore, yearsEmploy) ~ ccDebt + 
##     houseAge, data = data_mort)
## 
## Linear Regression Results for: yearsEmploy ~ ccDebt + houseAge
## File name: C:\Users\choi\Desktop\mort1.xdf
## Dependent variable(s): creditScore, yearsEmploy
## Total independent variables: 3 
## Number of valid observations: 10000
## Number of missing observations: 0 
##  
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 5.01e+00   7.68e-02   65.21  2.2e-16 ***
## ccDebt      3.46e-06   1.02e-05    0.34     0.73    
## houseAge    5.11e-04   2.67e-03    0.19     0.85    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 
## 
## Residual standard error: 2.02 on 9997 degrees of freedom
## Multiple R-squared: 1.52e-05 
## Adjusted R-squared: -0.000185 
## F-statistic: 0.0758 on 2 and 9997 DF,  p-value: 0.927 
## Condition number: 1.009

종속변수 자리에 2개의 변수를 넣게 되면, 위와 같이 두 변수에 종속변수가 되는 각각 다른 모형이, 한 번에 두 가지 만들어 지게 된다.

따라서, 위에는 creditScore ~ ccDebt + houseAge + yearsEmploy에 대한 summary이고,

아래는 yearsEmploy ~ ccDebt + houseAge에 대한 summary가 된다.


Appendix

rxLinMod

Usage

rxLinMod(formula, data, pweights = NULL, fweights = NULL, cube = FALSE,
cubePredictions = FALSE, rowSelection = NULL,
transforms = NULL, transformObjects = NULL,
transformFunc = NULL, transformVars = NULL,
transformPackages = NULL, transformEnvir = NULL,
dropFirst = FALSE, covCoef = FALSE, covData = FALSE, covariance = FALSE,
blocksPerRead = rxGetOption(“blocksPerRead”),
reportProgress = rxGetOption(“reportProgress”), verbose = 0,
computeContext = rxGetOption(“computeContext”), …)


Hankuk University of Foreign Studies. Dept of Statistics. Daewoo Choi Lab. Yeeseul Han.
한국외국어대학교 통계학과 최대우 연구실 한이슬
e-mail : han.lolove17@gmail.com