Running examples in ‘personalized-Ex.R’ failed
The error most likely occurred in:

> ### Name: check.overlap
> ### Title: Check propensity score overlap
> ### Aliases: check.overlap
> 
> ### ** Examples
> 
> library(personalized)
> 
> set.seed(123)
> n.obs  <- 500
> n.vars <- 25
> x <- matrix(rnorm(n.obs * n.vars, sd = 3), n.obs, n.vars)
> 
> 
> # simulate non-randomized treatment
> xbetat   <- 0.25 + 0.5 * x[,21] - 0.5 * x[,25]
> trt.prob <- exp(xbetat) / (1 + exp(xbetat))
> trt01    <- rbinom(n.obs, 1, prob = trt.prob)
> 
> # create function for fitting propensity score model
> prop.func <- function(x, trt)
+ {
+     # fit propensity score model
+     propens.model <- cv.glmnet(y = trt,
+                                x = x, family = "binomial")
+     pi.x <- predict(propens.model, s = "lambda.min",
+                     newx = x, type = "response")[,1]
+     pi.x
+ }
> 
> check.overlap(x = x,
+               trt = trt01,
+               propensity.func = prop.func)
> 
> # now add density plot with histogram
> check.overlap(x = x,
+               trt = trt01,
+               type = "both",
+               propensity.func = prop.func)
> 
> 
> # simulated non-randomized treatment with multiple levels
> xbetat_1   <- 0.15 + 0.5 * x[,21] - 0.25 * x[,25]
> xbetat_2   <- 0.15 - 0.5 * x[,11] + 0.25 * x[,15]
> trt.1.prob <- exp(xbetat_1) / (1 + exp(xbetat_1) + exp(xbetat_2))
> trt.2.prob <- exp(xbetat_2) / (1 + exp(xbetat_1) + exp(xbetat_2))
> trt.3.prob <- 1 - (trt.1.prob + trt.2.prob)
> prob.mat <- cbind(trt.1.prob, trt.2.prob, trt.3.prob)
> trt    <- apply(prob.mat, 1, function(rr) rmultinom(1, 1, prob = rr))
> trt    <- apply(trt, 2, function(rr) which(rr == 1))
> 
> # use multinomial logistic regression model with lasso penalty for propensity
> propensity.multinom.lasso <- function(x, trt)
+ {
+     if (!is.factor(trt)) trt <- as.factor(trt)
+     gfit <- cv.glmnet(y = trt, x = x, family = "multinomial")
+ 
+     # predict returns a matrix of probabilities:
+     # one column for each treatment level
+     propens <- drop(predict(gfit, newx = x, type = "response", s = "lambda.min",
+                             nfolds = 5, alpha = 0))
+ 
+     # return the probability corresponding to the
+     # treatment that was observed
+     probs <- propens[,match(levels(trt), colnames(propens))]
+ 
+     probs
+ }
> 
> check.overlap(x = x,
+               trt = trt,
+               type = "histogram",
+               propensity.func = propensity.multinom.lasso)
Error in apply(nz, 1, median) : dim(X) must have a positive length
Calls: check.overlap -> propensity.func -> cv.glmnet -> apply
Execution halted