% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/MeanimileNonparametricRegression.R
\name{MeanimileNonparametricRegression}
\alias{MeanimileNonparametricRegression}
\title{Estimate nonparametric conditional meanimile}
\usage{
MeanimileNonparametricRegression(
  X,
  Y,
  X0,
  d_tau,
  tau,
  h_x_loc,
  h_x_cdf,
  h_y_cdf,
  loss_type = c("square", "general"),
  lossDerivative = NULL,
  delta = NULL
)
}
\arguments{
\item{X}{A numeric matrix of covariates (n x d).}

\item{Y}{A numeric vector of the response variable.}

\item{X0}{A numeric matrix of evaluation points (m x d) where the curve should be estimated.}

\item{d_tau}{A function representing the density function of the
distributional weight function D_tau.}

\item{tau}{A numeric risk level/index. Argument of d_tau function.}

\item{h_x_loc}{A numeric vector of local spatial bandwidths for the covariates X.}

\item{h_x_cdf}{A numeric vector of bandwidths for the covariates X used in the CDF estimation.}

\item{h_y_cdf}{A numeric scalar bandwidth for the response variable Y used in the CDF estimation.}

\item{loss_type}{Character string specifying the loss formulation (\code{"square"} or \code{"general"}).}

\item{lossDerivative}{A function defining the derivative of the loss function. Required for \code{"general"}.}

\item{delta}{Optional numeric parameter for the loss function. Only for \code{"general"}.}
}
\value{
A numeric vector of length m, containing the estimated meanimile predictions at each point in X0.
}
\description{
Estimates a conditional meanimile in nonparametric way.
This function acts as a unified wrapper, allowing the user to seamlessly switch
between the square loss formulation and the general loss formulation.
}
\examples{
set.seed(123)
n <- 300

# 1. Simulate 1D Non-linear Data (Sine Wave)
X <- matrix(runif(n, -2, 2), ncol = 1)
Y <- sin(X[, 1] * 1.5) + rnorm(n, sd = 0.4)

# 2. Define Evaluation Grid
X0 <- matrix(seq(-2, 2, length.out = 50), ncol = 1)

# 3. Define Functions
d_tau_minvar <- function(u, tau) {
  (tau + 1) * u^tau
}
loss_deriv_expectile <- function(x, c, delta) {
  -2 * ifelse(x > c, delta, 1 - delta) * (x - c)
}

# 4. Fit Square Loss Nonparametric
preds_sq <- MeanimileNonparametricRegression(
  X = X, Y = Y, X0 = X0, d_tau = d_tau_minvar, tau = 2,
  h_x_loc = 0.4, h_x_cdf = 0.4, h_y_cdf = 0.4, loss_type = "square"
)

# 5. Fit General Loss Nonparametric (Expectile)
preds_gen <- MeanimileNonparametricRegression(
  X = X, Y = Y, X0 = X0, d_tau = d_tau_minvar, tau = 2,
  h_x_loc = 0.4, h_x_cdf = 0.4, h_y_cdf = 0.4, loss_type = "general",
  lossDerivative = loss_deriv_expectile, delta = 0.9
)
}
