Skip to content

Commit 6dc7b72

Browse files
committed
made a lot of test_rpsftm work.
closes #14
1 parent 4873ecd commit 6dc7b72

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

R/asOneFormula.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ asOneFormula <- function (..., omit = c(".", "pi"))
55
if (length(names))
66
eval(parse(text = paste("~", paste(names, collapse = "+")))[[1]])
77
else ~1
8+
#environments are not preseved. reassign outside of the function call
89
}
910

1011

R/rpsftm.R

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,10 @@ rpsftm <- function(formula, data, censor_time, subset, na.action, test = survdi
8787
# renamed time, status, censor_time, rx, arm as appropriate
8888
special <- c("strata","cluster")
8989
formula_list <- one_becomes_three(formula)
90+
all_var_formula <- asOneFormula(formula_list[1:3])
91+
environment(all_var_formula) <- environment(formula)
9092

91-
mf$formula <- asOneFormula(formula_list[1:3])
93+
mf$formula <- all_var_formula
9294

9395
mf$formula <- if (missing(data)) {
9496
terms(mf$formula, special)
@@ -360,6 +362,7 @@ rpsftm <- function(formula, data, censor_time, subset, na.action, test = survdi
360362
fit=fit,
361363
CI=c(lower$root,upper$root),
362364
Sstar=Sstar,
365+
formula_list=formula_list,
363366
#rand=rand_object,
364367
ans=ans,
365368
eval_z=eval_z),

R/untreated.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ untreated <- function(psi, response,treatment_matrix, rand_matrix, censor_time,
3030

3131

3232
nontreatment <- 1-apply(treatment_matrix,1,sum)
33-
treatment_matrix <- sweep(treatment_matrix,2, exp(psi), FUN="*")
33+
treatment_matrix <- sweep(treatment_matrix,1, exp(psi), FUN="*")
3434
treatment <- apply(treatment_matrix,1, sum)
3535

3636
u <- time * (nontreatment + treatment)

tests/testthat/test_rpsftm.R

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@ context("Test the rpsftm() function")
44

55

66

7+
test_that("check of test that with mixed data sources",{
8+
propX <- with(immdef,I(1-xoyrs/progyrs))
9+
fit <- lm(progyrs~propX, data=immdef)
10+
expect_is(fit$coefficients, "numeric")
11+
})
12+
13+
test_that("first basict fit",{
14+
fit <- rpsftm(Surv(progyrs, prog)~rand(I(1-xoyrs/progyrs)~imm),immdef, censyrs)
15+
expect_is(fit$psi, "numeric")
16+
})
17+
718

819
test_that("first basict fit with mixed data sources",{
920
propX <- with(immdef,I(1-xoyrs/progyrs))

0 commit comments

Comments
 (0)