choose_beta_init <- function(
    y, Wbar, Zmat,
    S_y, C_y, t,
    estWeight,
    estSigmaU_bar
) {


  n  <- length(y)
  WZ <- cbind(Wbar, Zmat)
  p  <- ncol(Wbar)
  q  <- ncol(Zmat)

  ## Naive OLS estimator

  b_naive <- as.numeric(
    solve(crossprod(WZ), crossprod(WZ, y))
  )

  ## GMM1: identity-weighted Z + phase score

  f_gmm1 <- function(b) {

    stopifnot(length(b) == ncol(WZ))

    ## Phase score
    S_phase <- PhaseGradient(
      b, S_y, C_y,
      WZ, t,
      estWeight
    )

    S_corrected = estim_eq_corrected(y,
                                     Wbar,
                                     Zmat,
                                     b,
                                     estSigmaU_bar)

    ## Stack scores
    S <- c(
      as.vector(S_corrected),
      as.vector(S_phase)
    )

    ## Identity-weighted GMM objective
    sum(S^2)
  }

  opt <- optim(
    par     = b_naive,
    fn      = f_gmm1,
    method  = "Nelder-Mead",
    control = list(maxit = 10000)
  )

  if (opt$convergence != 0) {
    warning("GMM1 optimisation did not fully converge")
  }

  return(opt$par)
}
