# lambdasearch: Leave-one-out optimization to find lambda In KRLS: Kernel-Based Regularized Least Squares

## Description

Function conducts leave-one-out optimization to find lambda using a golden search search with caching. This function is called internally by `krls`. It would normally not be called by the user directly.

## Usage

 ```1 2 3 4 5 6 7``` ```lambdasearch(L=NULL, U=NULL, y=NULL, Eigenobject=NULL, tol=NULL, noisy=FALSE, eigtrunc=NULL) ```

## Arguments

 `L` Non-negative scalar that determines the lower bound of the search window. Default is `NULL` which means that the lower bound is found using an algorithm (see details). `U` Positive scalar that determines the upper bound of the search window. Default is `NULL` which means that the upper bound is found using an algorithm (see details). `y` N by 1 matrix of outcomes. `Eigenobject` List that contains the eigenvalues and eigenvectors of the kernel matrix K. `tol` Positive scalar that determines the tolerance used in the optimization routine used to find lambda. Default is `NULL` which means that convergence is achieved when the difference in the sum of squared leave-one-out errors between the `i` and the `i+1` iteration is less than `N * 10^-3`. `noisy` If `TRUE`, the function will print details of the golden section search. `eigtrunc` Positive scalar value that determines truncation of eigenvalues for lamnda search window. See `krls` for details. Default is `NULL` which means no truncation.

## Details

By default, upper bound is found as follows: Set j to n, decrease by one until the following is longer true: sum(EigenValues / (EigenValues + j)) < 1.

By default, upper bound is found as follows: Get the position, q, of the eigenvalue that is closest to max(Eigenvalue)/1000. Set j to 0, increase in steps of 0.05 until the below is longer true: sum(EigenValues / (EigenValues + j)) > q.

## Value

A scalar that contains the lambda that minimizes the sum of squared leave-one-out errors.

## Author(s)

Jens Hainmueller (Stanford) and Chad Hazlett (MIT)

`krls`