If I understand correctly, you are thinking of some kind of model with this interaction:
Y ~ 0th + (Fac==1)*s(X)
If you want to "express the belief that X refers to Y only if Fac==1 " does not treat Fac as a factor , but as a numeric variable. In this case, you get numeric interaction and only one set of coefficients (when it is a factor where there are two). This type of model is a varying coefficient model .
# some data data <- data.frame(th = runif(100), X = runif(100), Y = runif(100), Fac = sample(0:1, 100, TRUE)) data$Fac<-as.numeric(as.character(data$Fac))
See the documentation for the by option in the ?s documentation
source share