Home > Software engineering >  Error when using `refund::prf` without model intercept
Error when using `refund::prf` without model intercept

Time:07-05

I'm trying to run a functional data analysis model with scalar-on-function and on scalar regression in R. But by removing the intercept I'm getting the following error (the example is based on this discussion),

library(refund)
data(DTI)
DTI1 <- DTI[DTI$visit==1 & complete.cases(DTI),]
par(mfrow=c(1,2))

fit_af <- pfr(pasat ~ -1  sex   case   af(cca, k=c(5, 8), bs="ps"), data = DTI1)

#Error in str2lang(x) : <text>:1:9: unexpected symbol
#1: pasat~0 sex
#            ^
#Calls: pfr -> formula -> formula.character -> str2lang

How can I remove the intercept from a pfr model?

CodePudding user response:

This is a bug. Running prf() in the debugging mode identifies the problem. When there is no intercept, it does:

if (!attr(tf, "intercept")) {
  newfrml <- paste(newfrml, "0", sep = "")
}

which I think should be fixed to

if (!attr(tf, "intercept")) {
  newfrml <- paste(newfrml, "0  ", sep = "")
}

Consider reporting this Stack Overflow thread, i.e., https://stackoverflow.com/q/72856108 to package maintainer Julia Wrobel: [email protected]


Note: This was tested using the latest refund_0.1-26 to date (released to CRAN on 2022-04-16).

  • Related