model {
# Noisy Input jags model for ni_spline_st
        for (i in 1:n_obs) {
          # Main likelihood
          y[i] ~ dnorm(mu_y[i], sigmasq_all[i]^-1)
          sigmasq_all[i] <- sigma_y^2 + y_err[i]^2 + NI_var_term[i]^2

          # Mean structure
          mu_y[i] <- l[i]

          # Model residuals
          residuals[i] <- y[i] - mu_y[i]
        }

      # Non-linear local component
       l <- B_st %*% b_st
       for (j in 1:n_knots_st) {
          b_st[j] ~ dnorm(0, sigma_beta^-2)
       }

      # Predictions
      l_pred <- B_st_pred %*% b_st
      for (i in 1:n_pred){
        mu_pred[i] <- l_pred[i]
        # Creating prediction intervals without uncertainty
        sigmasq_all_pred[i] <- sigma_y^2  + y_err_grid[i]^2 + NI_var_grid_term[i]^2
        y_pred[i] ~ dnorm(mu_pred[i], sigmasq_all_pred[i]^-1)
      }

      # Derivatives
      l_deriv <- B_st_deriv %*% b_st
      for (i in 1:n_obs){
        mu_deriv[i] <- l_deriv[i]
      }

      l_pred_deriv <- B_st_deriv_pred %*% b_st
      for (i in 1:n_pred){
        mu_pred_deriv[i] <- l_pred_deriv[i]
      }

      # Priors
        sigma_beta ~ dt(0, 1^-2, 1)T(0,)
        sigma_y ~ dt(0, 1^-2, 1)T(0,)
    }
