def suggest_burn(self): """ Suggest a number of burn-in iterations. For Gaussian models this will be based on the simulated values of log-likelihood. For other models it will be a fixed percentage of the draws. """ loglike = self.log_likelihood if loglike is None: burn = self.niter / 10 else: burn = R.suggest_burn(loglike) return burn
def coefficient_positive_probability(self, burn=None): """ Args: burn: The number of MCMC iterations to discard as burn-in. Returns: A pd.Series containing the marginal probability that each coefficient is positive. """ if burn is None: burn = R.suggest_burn(self.log_likelihood) probs = coefficient_positive_probability( self._coefficient_draws[burn:, :]) return pd.Series(probs, index=self.xnames)
def inclusion_probs(self, burn=None): """ Args: burn: The number of MCMC iterations to discard as burn-in. Returns: A pd.Series containing the marginal probability that each coefficient is nonzero. The series is indexed by the set of variable names. """ if burn is None: burn = R.suggest_burn(self.log_likelihood) probs = compute_inclusion_probabilities( self._coefficient_draws[burn:, ]) return pd.Series(probs, index=self.xnames)
def predict(self, newdata, burn=None, seed=None): """ Return an LmSpikePrediciton object. """ if burn is None: burn = R.suggest_burn(self.log_likelihood) if seed is not None: boom.GlobalRng.rng.seed(int(seed)) if isinstance(newdata, np.ndarray) and len(newdata.shape) == 1: newdata = newdata.reshape(1, -1) if isinstance(newdata, np.ndarray) and newdata.shape[1] == self.xdim: predictors = newdata else: predictors = patsy.build_design_matrices([self._x_design_info], data=newdata)[0] return self._coefficient_draws[burn:, :] @ predictors.T
def coefficient_positive_probability(self, burn=None): """ Args: burn: The number of MCMC iterations to discard as burn-in. Returns: A pd.Series containing the marginal probability that each coefficient is positive. """ if burn is None: burn = R.suggest_burn(self.log_likelihood) draws = self._coefficient_draws probs = np.array( [np.mean(draws[burn:, i] > 0) for i in range(draws.shape[1])]) return pd.Series(probs, index=self.xnames)
def inclusion_probs(self, burn=None): """ Args: burn: The number of MCMC iterations to discard as burn-in. Returns: A pd.Series containing the marginal probability that each coefficient is nonzero. The series is indexed by the set of variable names. """ if burn is None: burn = R.suggest_burn(self.log_likelihood) draws = self._coefficient_draws probs = np.array( [np.mean(draws[burn:, i] != 0) for i in range(draws.shape[1])]) return pd.Series(probs, index=self.xnames)
def suggest_burn(self): return R.suggest_burn(-1 * self._residual_sd_draws)