R‎ > ‎R‎ > ‎

Alternatives to inprod functions

WinBUGS is cumbersome when it comes to programming linear models because its built-in inner product function, inprod, is VERY slow. Often, the solution is to manually input each independent variable and its coefficient. I've automated this process to make it easier to add and remove variables from a linear model in a more automated fashion.

Using inprod or "manual" method

#Using inprod
model1 <- function() {
  #data model
    for (i in 1:N){
    Y[i] ~ dnorm(mu[i], tau)
    mu[i] <- inprod(beta1[], X[i,])
    }
  #priors, etc.
    
#Using manual coding
model2 <- function() {
  #data model
    for (i in 1:N){
    Y[i] ~ dnorm(mu[i], tau)
    beta1[1]*X1[i,1] +
    beta1[2]*X1[i,2]
    }
  #priors, etc.

Automated Method

#Code to come


Comments