get the conditional variance of Y on X for given x
get_conditional_var.RdVectorized implementation using matrix operations for improved performance. For large datasets (n > 10,000), memory usage is approximately 8n^2 bytes.
Arguments
- X
A numerical vector representing the sample data of variable X.
- Y
A numerical vector representing the sample data of variable Y.
- x
The specific point at which the conditional variance is to be calculated.
- h
A bandwidth parameter used in the kernel function for smoothing.
- kernel_func
A kernel function used to weigh observations in the neighborhood of point x.
Value
Returns a non-negative scalar representing the estimated conditional variance of Y given X at the point x. Returns 0 if the computed variance is negative.
Details
Performance: Achieves >10x speedup for n=1,000 and >20x speedup for n=10,000 compared to the original loop-based implementation.
Memory: Allocates an n x n distance matrix. For n=10,000, requires ~800 MB. Issues a warning when estimated memory exceeds 4 GB and stops with an error when estimated memory exceeds 10 GB.