64
64
# ' x2 <- rnorm(n)
65
65
# ' x3 <- rnorm(n)
66
66
# ' x4 <- as.numeric(rbinom(n,1,0.5))
67
- # ' x5 <- as.numeric(sample(1:3,n,replace=T ))
67
+ # ' x5 <- as.numeric(sample(1:3,n,replace=TRUE ))
68
68
# ' X <- cbind(x1,x2,x3,x4,x5)
69
69
# ' p <- ncol(X)
70
70
# ' g <- function(x) {ifelse(x[,5]==1,2,ifelse(x[,5]==2,-1,4))}
80
80
# ' snr <- 4
81
81
# ' y <- E_XZ + rnorm(n, 0, 1)*(sd(E_XZ)/snr)
82
82
# ' X <- as.data.frame(X)
83
- # ' X$x4 <- factor(X$x4, ordered = T )
84
- # ' X$x5 <- factor(X$x5, ordered = T )
83
+ # ' X$x4 <- factor(X$x4, ordered = TRUE )
84
+ # ' X$x5 <- factor(X$x5, ordered = TRUE )
85
85
# ' test_set_pct <- 0.2
86
86
# ' n_test <- round(test_set_pct*n)
87
87
# ' n_train <- n - n_test
@@ -766,7 +766,7 @@ bcf <- function(X_train, Z_train, y_train, pi_train = NULL, group_ids_train = NU
766
766
# ' x2 <- rnorm(n)
767
767
# ' x3 <- rnorm(n)
768
768
# ' x4 <- as.numeric(rbinom(n,1,0.5))
769
- # ' x5 <- as.numeric(sample(1:3,n,replace=T ))
769
+ # ' x5 <- as.numeric(sample(1:3,n,replace=TRUE ))
770
770
# ' X <- cbind(x1,x2,x3,x4,x5)
771
771
# ' p <- ncol(X)
772
772
# ' g <- function(x) {ifelse(x[,5]==1,2,ifelse(x[,5]==2,-1,4))}
@@ -782,8 +782,8 @@ bcf <- function(X_train, Z_train, y_train, pi_train = NULL, group_ids_train = NU
782
782
# ' snr <- 4
783
783
# ' y <- E_XZ + rnorm(n, 0, 1)*(sd(E_XZ)/snr)
784
784
# ' X <- as.data.frame(X)
785
- # ' X$x4 <- factor(X$x4, ordered = T )
786
- # ' X$x5 <- factor(X$x5, ordered = T )
785
+ # ' X$x4 <- factor(X$x4, ordered = TRUE )
786
+ # ' X$x5 <- factor(X$x5, ordered = TRUE )
787
787
# ' test_set_pct <- 0.2
788
788
# ' n_test <- round(test_set_pct*n)
789
789
# ' n_train <- n - n_test
@@ -928,7 +928,7 @@ predict.bcf <- function(bcf, X_test, Z_test, pi_test = NULL, group_ids_test = NU
928
928
# ' Extract raw sample values for each of the random effect parameter terms.
929
929
# '
930
930
# ' @param object Object of type `bcf` containing draws of a Bayesian causal forest model and associated sampling outputs.
931
- # '
931
+ # ' @param ... Other parameters to be used in random effects extraction
932
932
# ' @return List of arrays. The alpha array has dimension (`num_components`, `num_samples`) and is simply a vector if `num_components = 1`.
933
933
# ' The xi and beta arrays have dimension (`num_components`, `num_groups`, `num_samples`) and is simply a matrix if `num_components = 1`.
934
934
# ' The sigma array has dimension (`num_components`, `num_samples`) and is simply a vector if `num_components = 1`.
@@ -940,7 +940,7 @@ predict.bcf <- function(bcf, X_test, Z_test, pi_test = NULL, group_ids_test = NU
940
940
# ' x2 <- rnorm(n)
941
941
# ' x3 <- rnorm(n)
942
942
# ' x4 <- as.numeric(rbinom(n,1,0.5))
943
- # ' x5 <- as.numeric(sample(1:3,n,replace=T ))
943
+ # ' x5 <- as.numeric(sample(1:3,n,replace=TRUE ))
944
944
# ' X <- cbind(x1,x2,x3,x4,x5)
945
945
# ' p <- ncol(X)
946
946
# ' g <- function(x) {ifelse(x[,5]==1,2,ifelse(x[,5]==2,-1,4))}
@@ -955,13 +955,13 @@ predict.bcf <- function(bcf, X_test, Z_test, pi_test = NULL, group_ids_test = NU
955
955
# ' E_XZ <- mu_x + Z*tau_x
956
956
# ' snr <- 3
957
957
# ' group_ids <- rep(c(1,2), n %/% 2)
958
- # ' rfx_coefs <- matrix(c(-1, -1, 1, 1),nrow=2,byrow=T )
958
+ # ' rfx_coefs <- matrix(c(-1, -1, 1, 1), nrow=2, byrow=TRUE )
959
959
# ' rfx_basis <- cbind(1, runif(n, -1, 1))
960
960
# ' rfx_term <- rowSums(rfx_coefs[group_ids,] * rfx_basis)
961
961
# ' y <- E_XZ + rfx_term + rnorm(n, 0, 1)*(sd(E_XZ)/snr)
962
962
# ' X <- as.data.frame(X)
963
- # ' X$x4 <- factor(X$x4, ordered = T )
964
- # ' X$x5 <- factor(X$x5, ordered = T )
963
+ # ' X$x4 <- factor(X$x4, ordered = TRUE )
964
+ # ' X$x5 <- factor(X$x5, ordered = TRUE )
965
965
# ' test_set_pct <- 0.2
966
966
# ' n_test <- round(test_set_pct*n)
967
967
# ' n_train <- n - n_test
@@ -991,7 +991,7 @@ predict.bcf <- function(bcf, X_test, Z_test, pi_test = NULL, group_ids_test = NU
991
991
# ' Z_test = Z_test, pi_test = pi_test, group_ids_test = group_ids_test,
992
992
# ' rfx_basis_test = rfx_basis_test,
993
993
# ' num_gfr = 100, num_burnin = 0, num_mcmc = 100,
994
- # ' sample_sigma_leaf_mu = T , sample_sigma_leaf_tau = F )
994
+ # ' sample_sigma_leaf_mu = TRUE , sample_sigma_leaf_tau = FALSE )
995
995
# ' rfx_samples <- getRandomEffectSamples(bcf_model)
996
996
getRandomEffectSamples.bcf <- function (object , ... ){
997
997
result = list ()
@@ -1026,7 +1026,7 @@ getRandomEffectSamples.bcf <- function(object, ...){
1026
1026
# ' x2 <- rnorm(n)
1027
1027
# ' x3 <- rnorm(n)
1028
1028
# ' x4 <- as.numeric(rbinom(n,1,0.5))
1029
- # ' x5 <- as.numeric(sample(1:3,n,replace=T ))
1029
+ # ' x5 <- as.numeric(sample(1:3,n,replace=TRUE ))
1030
1030
# ' X <- cbind(x1,x2,x3,x4,x5)
1031
1031
# ' p <- ncol(X)
1032
1032
# ' g <- function(x) {ifelse(x[,5]==1,2,ifelse(x[,5]==2,-1,4))}
@@ -1041,13 +1041,13 @@ getRandomEffectSamples.bcf <- function(object, ...){
1041
1041
# ' E_XZ <- mu_x + Z*tau_x
1042
1042
# ' snr <- 3
1043
1043
# ' group_ids <- rep(c(1,2), n %/% 2)
1044
- # ' rfx_coefs <- matrix(c(-1, -1, 1, 1),nrow=2,byrow=T )
1044
+ # ' rfx_coefs <- matrix(c(-1, -1, 1, 1), nrow=2, byrow=TRUE )
1045
1045
# ' rfx_basis <- cbind(1, runif(n, -1, 1))
1046
1046
# ' rfx_term <- rowSums(rfx_coefs[group_ids,] * rfx_basis)
1047
1047
# ' y <- E_XZ + rfx_term + rnorm(n, 0, 1)*(sd(E_XZ)/snr)
1048
1048
# ' X <- as.data.frame(X)
1049
- # ' X$x4 <- factor(X$x4, ordered = T )
1050
- # ' X$x5 <- factor(X$x5, ordered = T )
1049
+ # ' X$x4 <- factor(X$x4, ordered = TRUE )
1050
+ # ' X$x5 <- factor(X$x5, ordered = TRUE )
1051
1051
# ' test_set_pct <- 0.2
1052
1052
# ' n_test <- round(test_set_pct*n)
1053
1053
# ' n_train <- n - n_test
@@ -1077,7 +1077,7 @@ getRandomEffectSamples.bcf <- function(object, ...){
1077
1077
# ' Z_test = Z_test, pi_test = pi_test, group_ids_test = group_ids_test,
1078
1078
# ' rfx_basis_test = rfx_basis_test,
1079
1079
# ' num_gfr = 100, num_burnin = 0, num_mcmc = 100,
1080
- # ' sample_sigma_leaf_mu = T , sample_sigma_leaf_tau = F )
1080
+ # ' sample_sigma_leaf_mu = TRUE , sample_sigma_leaf_tau = FALSE )
1081
1081
# ' # bcf_json <- convertBCFModelToJson(bcf_model)
1082
1082
convertBCFModelToJson <- function (object ){
1083
1083
jsonobj <- createCppJson()
@@ -1160,7 +1160,7 @@ convertBCFModelToJson <- function(object){
1160
1160
# ' x2 <- rnorm(n)
1161
1161
# ' x3 <- rnorm(n)
1162
1162
# ' x4 <- as.numeric(rbinom(n,1,0.5))
1163
- # ' x5 <- as.numeric(sample(1:3,n,replace=T ))
1163
+ # ' x5 <- as.numeric(sample(1:3,n,replace=TRUE ))
1164
1164
# ' X <- cbind(x1,x2,x3,x4,x5)
1165
1165
# ' p <- ncol(X)
1166
1166
# ' g <- function(x) {ifelse(x[,5]==1,2,ifelse(x[,5]==2,-1,4))}
@@ -1175,10 +1175,13 @@ convertBCFModelToJson <- function(object){
1175
1175
# ' E_XZ <- mu_x + Z*tau_x
1176
1176
# ' snr <- 3
1177
1177
# ' group_ids <- rep(c(1,2), n %/% 2)
1178
- # ' rfx_coefs <- matrix(c(-1, -1, 1, 1),nrow=2,byrow=T )
1178
+ # ' rfx_coefs <- matrix(c(-1, -1, 1, 1), nrow=2, byrow=TRUE )
1179
1179
# ' rfx_basis <- cbind(1, runif(n, -1, 1))
1180
1180
# ' rfx_term <- rowSums(rfx_coefs[group_ids,] * rfx_basis)
1181
1181
# ' y <- E_XZ + rfx_term + rnorm(n, 0, 1)*(sd(E_XZ)/snr)
1182
+ # ' X <- as.data.frame(X)
1183
+ # ' X$x4 <- factor(X$x4, ordered = TRUE)
1184
+ # ' X$x5 <- factor(X$x5, ordered = TRUE)
1182
1185
# ' test_set_pct <- 0.2
1183
1186
# ' n_test <- round(test_set_pct*n)
1184
1187
# ' n_train <- n - n_test
@@ -1206,9 +1209,9 @@ convertBCFModelToJson <- function(object){
1206
1209
# ' pi_train = pi_train, group_ids_train = group_ids_train,
1207
1210
# ' rfx_basis_train = rfx_basis_train, X_test = X_test,
1208
1211
# ' Z_test = Z_test, pi_test = pi_test, group_ids_test = group_ids_test,
1209
- # ' rfx_basis_test = rfx_basis_test, ordered_cat_vars = c(4,5),
1212
+ # ' rfx_basis_test = rfx_basis_test,
1210
1213
# ' num_gfr = 100, num_burnin = 0, num_mcmc = 100,
1211
- # ' sample_sigma_leaf_mu = T , sample_sigma_leaf_tau = F )
1214
+ # ' sample_sigma_leaf_mu = TRUE , sample_sigma_leaf_tau = FALSE )
1212
1215
# ' # saveBCFModelToJsonFile(bcf_model, "test.json")
1213
1216
saveBCFModelToJsonFile <- function (object , filename ){
1214
1217
# Convert to Json
@@ -1232,7 +1235,7 @@ saveBCFModelToJsonFile <- function(object, filename){
1232
1235
# ' x2 <- rnorm(n)
1233
1236
# ' x3 <- rnorm(n)
1234
1237
# ' x4 <- as.numeric(rbinom(n,1,0.5))
1235
- # ' x5 <- as.numeric(sample(1:3,n,replace=T ))
1238
+ # ' x5 <- as.numeric(sample(1:3,n,replace=TRUE ))
1236
1239
# ' X <- cbind(x1,x2,x3,x4,x5)
1237
1240
# ' p <- ncol(X)
1238
1241
# ' g <- function(x) {ifelse(x[,5]==1,2,ifelse(x[,5]==2,-1,4))}
@@ -1247,10 +1250,13 @@ saveBCFModelToJsonFile <- function(object, filename){
1247
1250
# ' E_XZ <- mu_x + Z*tau_x
1248
1251
# ' snr <- 3
1249
1252
# ' group_ids <- rep(c(1,2), n %/% 2)
1250
- # ' rfx_coefs <- matrix(c(-1, -1, 1, 1),nrow=2,byrow=T )
1253
+ # ' rfx_coefs <- matrix(c(-1, -1, 1, 1), nrow=2, byrow=TRUE )
1251
1254
# ' rfx_basis <- cbind(1, runif(n, -1, 1))
1252
1255
# ' rfx_term <- rowSums(rfx_coefs[group_ids,] * rfx_basis)
1253
1256
# ' y <- E_XZ + rfx_term + rnorm(n, 0, 1)*(sd(E_XZ)/snr)
1257
+ # ' X <- as.data.frame(X)
1258
+ # ' X$x4 <- factor(X$x4, ordered = TRUE)
1259
+ # ' X$x5 <- factor(X$x5, ordered = TRUE)
1254
1260
# ' test_set_pct <- 0.2
1255
1261
# ' n_test <- round(test_set_pct*n)
1256
1262
# ' n_train <- n - n_test
@@ -1278,9 +1284,9 @@ saveBCFModelToJsonFile <- function(object, filename){
1278
1284
# ' pi_train = pi_train, group_ids_train = group_ids_train,
1279
1285
# ' rfx_basis_train = rfx_basis_train, X_test = X_test,
1280
1286
# ' Z_test = Z_test, pi_test = pi_test, group_ids_test = group_ids_test,
1281
- # ' rfx_basis_test = rfx_basis_test, ordered_cat_vars = c(4,5),
1287
+ # ' rfx_basis_test = rfx_basis_test,
1282
1288
# ' num_gfr = 100, num_burnin = 0, num_mcmc = 100,
1283
- # ' sample_sigma_leaf_mu = T , sample_sigma_leaf_tau = F )
1289
+ # ' sample_sigma_leaf_mu = TRUE , sample_sigma_leaf_tau = FALSE )
1284
1290
# ' # bcf_json <- convertBCFModelToJson(bcf_model)
1285
1291
# ' # bcf_model_roundtrip <- createBCFModelFromJson(bcf_json)
1286
1292
createBCFModelFromJson <- function (json_object ){
@@ -1368,7 +1374,7 @@ createBCFModelFromJson <- function(json_object){
1368
1374
# ' x2 <- rnorm(n)
1369
1375
# ' x3 <- rnorm(n)
1370
1376
# ' x4 <- as.numeric(rbinom(n,1,0.5))
1371
- # ' x5 <- as.numeric(sample(1:3,n,replace=T ))
1377
+ # ' x5 <- as.numeric(sample(1:3,n,replace=TRUE ))
1372
1378
# ' X <- cbind(x1,x2,x3,x4,x5)
1373
1379
# ' p <- ncol(X)
1374
1380
# ' g <- function(x) {ifelse(x[,5]==1,2,ifelse(x[,5]==2,-1,4))}
@@ -1383,10 +1389,13 @@ createBCFModelFromJson <- function(json_object){
1383
1389
# ' E_XZ <- mu_x + Z*tau_x
1384
1390
# ' snr <- 3
1385
1391
# ' group_ids <- rep(c(1,2), n %/% 2)
1386
- # ' rfx_coefs <- matrix(c(-1, -1, 1, 1),nrow=2,byrow=T )
1392
+ # ' rfx_coefs <- matrix(c(-1, -1, 1, 1), nrow=2, byrow=TRUE )
1387
1393
# ' rfx_basis <- cbind(1, runif(n, -1, 1))
1388
1394
# ' rfx_term <- rowSums(rfx_coefs[group_ids,] * rfx_basis)
1389
1395
# ' y <- E_XZ + rfx_term + rnorm(n, 0, 1)*(sd(E_XZ)/snr)
1396
+ # ' X <- as.data.frame(X)
1397
+ # ' X$x4 <- factor(X$x4, ordered = TRUE)
1398
+ # ' X$x5 <- factor(X$x5, ordered = TRUE)
1390
1399
# ' test_set_pct <- 0.2
1391
1400
# ' n_test <- round(test_set_pct*n)
1392
1401
# ' n_train <- n - n_test
@@ -1414,9 +1423,9 @@ createBCFModelFromJson <- function(json_object){
1414
1423
# ' pi_train = pi_train, group_ids_train = group_ids_train,
1415
1424
# ' rfx_basis_train = rfx_basis_train, X_test = X_test,
1416
1425
# ' Z_test = Z_test, pi_test = pi_test, group_ids_test = group_ids_test,
1417
- # ' rfx_basis_test = rfx_basis_test, ordered_cat_vars = c(4,5),
1426
+ # ' rfx_basis_test = rfx_basis_test,
1418
1427
# ' num_gfr = 100, num_burnin = 0, num_mcmc = 100,
1419
- # ' sample_sigma_leaf_mu = T , sample_sigma_leaf_tau = F )
1428
+ # ' sample_sigma_leaf_mu = TRUE , sample_sigma_leaf_tau = FALSE )
1420
1429
# ' # saveBCFModelToJsonFile(bcf_model, "test.json")
1421
1430
# ' # bcf_model_roundtrip <- createBCFModelFromJsonFile("test.json")
1422
1431
createBCFModelFromJsonFile <- function (json_filename ){
0 commit comments