Dealing with unknown data with rstan/ODE

I have a general question with regard to using stan to solve ODE problems. In the simple harmonic oscillator example, both y[1] and y[2] are supplied during the model fitting. In case of when only one variable can be observed (i.e. only y[1] is known), how should the code by modified in order to model the system? Can you put the whole variable in the parameters chunk and how would achieve that? A lot thanks!

functions {
  real[] sho(real t, real[] y, real[] theta, real[] x_r, int[] x_i) {
    real dy1_dt = y[2];
    real dy2_dt = -y[1] - theta[1] * y[2];
    return { dy1_dt, dy2_dt };
  }
}
data {
  int<lower = 0> T;
  real t0;
  real<lower = t0> ts[T];
  real y_hat[T, 2];
  real y0[2];
}
transformed data {
  real x_r[0];
  int x_i[0];
}
parameters {
  real theta[1];
  real<lower = 0> sigma;
}
transformed parameters {
  real y[T, 2] = integrate_ode_bdf(sho, y0, 0.0, ts, theta, x_r, x_i);
}
model {
  sigma ~ normal(0.1, 0.1);
  theta ~ normal(0.15, 0.1);
  y0 ~ normal({1.0, 0.0}, 0.1);
 
  y_hat[, 1] ~ normal(y[, 1],  sigma);
  y_hat[, 2] ~ normal(y[, 2],  sigma);
}
generated quantities {
}

If you only observe the first component, that’s easy.

Change:

y_hat[, 1] ~ normal(y[, 1],  sigma);
y_hat[, 2] ~ normal(y[, 2],  sigma);

to

y_hat[, 1] ~ normal(y[, 1],  sigma);

The question becomes is this enough information to infer all the parameters? That’s something problem dependent. In this case it probably is.

Thanks for your reply. This clear my misunderstanding that all data (y) in user defined function need to be supplied when calling stan/sampling function, but I should only need the initial value for the integrator to work and anything I want to fit to the model. I get similar solution by talking to jandraor in his post on a different topic. Thanks to both of you.