This is related to this post.
I want to succinctly write a formula with many variables to estimate a non-parametric model, and I used the method provided by the post above. However, I found it does not work with np::npplregbw
.
As a start, the formula in linear model works well
df<-data.frame(y=rnorm(10),x1=rnorm(10),x2=rnorm(10),x3=rnorm(10),x4=rnorm(10),
x5=rnorm(10))
## Create a formula for a model with a large number of variables:
xnam <- paste("x", 1:4, sep="")
fmla <- as.formula(paste("y ~ ", paste(xnam, collapse= "+")))
## This works
m <- lm(formula = fmla, data=df)
However, if we continue from the code above, and try to get a formula that is suitable for np:npplregbw
xnam2 <- paste("y ~ ", paste(xnam, collapse= "+"))
fmla <- as.formula(paste(xnam2, '|x5'))
## This returns an error
bw <- np::npplregbw(formula = fmla, data=df)
This returns an error "Error in npplregbw.formula(fmla, data = df) : invoked with improper formula, please see npplregbw documentation for proper use"
But the formula itself should work, as is seen below
print(fmla) ## Gets y ~ x1 + x2 + x3 + x4 | x5
## This also works
bw <- np::npplregbw(y ~ x1 + x2 + x3 + x4 | x5, data=df)
Can someone explain why this happens and how to solve this?