@@ -142,16 +142,23 @@ test_that("kmeans", {
142142 expect_equal(sort(collect(distinct(select(cluster , " prediction" )))$ prediction ), c(0 , 1 ))
143143})
144144
145- test_that(" survreg vs survival::survreg" , {
146- data <- list (list (4 , 1 , 0 , 0 ), list (3 , 1 , 2 , 0 ), list (1 , 1 , 1 , 0 ),
147- list (1 , 0 , 1 , 0 ), list (2 , 1 , 1 , 1 ), list (2 , 1 , 0 , 1 ), list (3 , 0 , 0 , 1 ))
148- df <- createDataFrame(sqlContext , data , c(" time" , " status" , " x" , " sex" ))
149- model <- survreg(Surv(time , status ) ~ x + sex , df )
145+ test_that(" SparkR::survreg vs survival::survreg" , {
146+ library(survival )
147+ data(ovarian )
148+ df <- suppressWarnings(createDataFrame(sqlContext , ovarian ))
149+
150+ model <- SparkR :: survreg(Surv(futime , fustat ) ~ ecog_ps + rx , df )
150151 stats <- summary(model )
151- coefs <- as.vector(stats $ coefficients [, 1 ])
152- rCoefs <- c(1.3149571 , - 0.1903409 , - 0.2532618 , - 1.1599802 )
152+ coefs <- as.vector(stats $ coefficients [, 1 ][1 : 3 ])
153+ scale <- exp(stats $ coefficients [, 1 ][4 ])
154+
155+ rModel <- survival :: survreg(Surv(futime , fustat ) ~ ecog.ps + rx , ovarian )
156+ rCoefs <- as.vector(coef(rModel ))
157+ rScale <- rModel $ scale
158+
153159 expect_true(all(abs(rCoefs - coefs ) < 1e-4 ))
160+ expect_true(abs(rScale - scale ) < 1e-4 )
154161 expect_true(all(
155162 rownames(stats $ coefficients ) ==
156- c(" (Intercept)" , " x " , " sex " , " Log(scale)" )))
163+ c(" (Intercept)" , " ecog_ps " , " rx " , " Log(scale)" )))
157164})
0 commit comments