In experiments I did ages ago (Feb 2014) at Andrew's behest,
Stan did outperform glm() for large enough problems and even
outperformed lm() when the model was coded directly as follows
and called with init=0 and all tolerances at 1e-8:
data {
int<lower=0> N;
int<lower=1> K;
vector[N] y;
matrix[N,K] x;
}
parameters {
vector[K] beta;
}
transformed parameters {
real<lower=0> squared_error;
squared_error <- dot_self(y - x * beta);
}
model {
increment_log_prob(-squared_error);
}
generated quantities {
real<lower=0> sigma_squared;
sigma_squared <- squared_error / N;
}
You could use (N - 1) if you wnat the usual estimate
of sigma^2.
This should only get faster as our matrix operations like
dot_self are further optimized.
I don't seem to have saved any of the output of the runs
and can't find it in email. You had to get pretty big
problems that took a couple minutes to run before Stan
was faster.
For logistic regression, I just used:
data {
int<lower=1> K; // number of predictors (including intercept)
int<lower=0> N; // number of observations
matrix[N,K] x; // predictors
int<lower=0,upper=1> y[N]; // outcomes
}
parameters {
vector[K] beta; // coeffs
}
model {
y ~ bernoulli_logit(x * beta);
}
- Bob