Combine multiple individual models?

28 views
Skip to first unread message

Scott Brown

unread,
Oct 6, 2023, 10:47:12 AM10/6/23
to nimble-users
Hello,

I have a Gaussian Process model, and I would like to include the output of this model as a linear factor in a GLM.  As part of my workflow, I have already defined the basic format of the GLM as a `nimbleCode`, and I have defined the GP as a `nimbleCode` as well.  It would be super nice if there were some way to create a new `nimbleCode` that does something vaguely like: 
```
    covariates <- stack(matrixOfCovariates, myGPModel["s"])
    myGLMModel["lambda"] <- rowSum(covariates)
```
Basically, the desire is to not have to copy-pasta my code into a huge wall of a model, when the GLM and the GP are already defined, and the tie between them is this single additive bit.

Is there any way to combine multiple individual models into a "large" model?

Cheers,
-Scott!

Perry de Valpine

unread,
Oct 9, 2023, 4:18:10 PM10/9/23
to Scott Brown, nimble-users
Hi Scott,
Specifically what you're suggesting does not exist. We have thought about ideas like it, but they have never been created.
The nimbleCode function is essentially the same as R's native quote function. 

Here is a stack function that will put together two results from nimbleCode (or quote):

stack <- function(a, b) {
   unpack <- \(x) if(x[[1]]=='{') as.list(x)[-1] else x
   as.call(c(quote(`{`), unpack(a), unpack(b)))
}

c1 <- nimbleCode({a ~ dnorm(0,1)}) # arbitrary code within {}
c2 <- nimbleCode(b ~ dexp(1)) # a single line
stack(c1, c2)

It's not as general as what you're sketching, but maybe it will give you something to compose models from pieces in a useful way.

HTH
Perry



--
You received this message because you are subscribed to the Google Groups "nimble-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nimble-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nimble-users/524c110b-a3c1-47fd-8a01-78478ad9ee84n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages