Error in terms.formula(formula) : '.' in formula and no 'data' argument
As my comment states, this looks like a bug in the non-exported function neuralnet:::generate.initial.variables
. As a work around, just build a long formula from the names of dt
, excluding y
, e.g.
n <- names(dt)
f <- as.formula(paste("y ~", paste(n[!n %in% "y"], collapse = " + ")))
f
## gives
> f
y ~ x1 + x2
## fit model using `f`
model <- neuralnet(f, data = dt, hidden=10, threshold=0.01)
> model
Call: neuralnet(formula = f, data = dt, hidden = 10, threshold = 0.01)
1 repetition was calculated.
Error Reached Threshold Steps
1 53975276.25 0.00857558698 1967
Offering a simpler alternative to the previous answer, you can create a formula from names of dt
using reformulate()
:
f <- reformulate(setdiff(colnames(dt), "y"), response="y")
reformulate()
doesn't require the use of paste()
and automatically adds the terms together.