def _arma_predict_in_sample(start, end, endog, resid, k_ar, method):
    """
    Pre- and in-sample fitting for ARMA.
    """
    if 'mle' in method:
        fittedvalues = endog - resid
    else:
        fittedvalues = endog[k_ar:] - resid
    fv_start = start
    if 'mle' not in method:
        fv_start -= k_ar
    fv_end = min(len(fittedvalues), end + 1)
    return fittedvalues[fv_start:fv_end]
