library(earth)
y <- cumsum(sample(c(-1, 1),100, TRUE))
p1 <- cumsum(sample(c(-1, 1),100, TRUE))
p2 <- cumsum(sample(c(-1, 1),100, TRUE))
p3 <- cumsum(sample(c(-1, 1),100, TRUE))
n1 <- cumsum(sample(c(-1, 1),100, TRUE))
n2 <- cumsum(sample(c(-1, 1),100, TRUE))
df1 <- data.frame(y,p1,p2,p3,n1,n2)
df1
I am using earth for a non linear regression. I have some constraints where
the maximum number of splines in the first variable is 2, the second variable is 3, the third variable is 4 etc. Also the p variables have to have a positive slope and the n variables a negative slope.
I can set a global maximum for the number of splines:
fit <- earth(y ~ ., data = df1,nprune=50,trace=5)
but I am having problems setting a maximum number of splines and slope sign for each variable individually. I tried:
fit <- earth(y ~ ., data = df1,nprune=c(2,3,4,5,6))
plotmo(fit)
summary(fit, digits = 2, style = "pmax")
but I get an error.
How can I control the max number of splines and slope sign for each variables so as to avoid Spurious Regression?
I was thinking that there may be a way to set conditions before the model selection process. Possibly by making some slight alteration of the earth function but I have not yet been able to work out ho to do it. This function is hidden but can be viewed as below:
To view the hidden S3 functions:
methods(earth)
getAnywhere(earth.default)
getAnywhere(earth.formula)
Here is the link for viewing a hiddden S3 function: How can I view the source code for a function?
To view all the code (R, C, Fortran etc) download the .tar.gz source package from CRAN, unpack it and the R source code is available in the "R" subdirectory.
also: cerebralmastication.com/2009/02/finding-the-source-in-r
to view S4 functions use:
showMethods()
getMethod()
Thank you for your help.