fit_periodic_loess {tricycle} | R Documentation

## Fit periodic loess line with circular predictor

### Description

The function will fit a loess line using cell cycle position and other variables, such as expression levels of a gene or log-transformed totalUMIs numbers. The circular nature of cell cycle position is taken into account by making 3 copies inside the function. For convenience, the function will also return a scatter plot with fitted line if needed.

### Arguments

`theta.v` | The cell cycle position - a numeric vector with range between 0 to 2pi.
`y` | The response variable - a numeric vector with the same length as `theta.v`.
`span` | The parameter α which controls the degree of smoothing. See `loess`. Default: 0.3
`length.out` | The number of data points on the fitted lines to be output in the prediction data.frame. Default: 200
`plot` | If `TRUE`, a `ggplot` scatter plot will be included in the output list. The figure will plot y ~ theta.v with points and the fitted `loess` line. Default: FALSE
`fig.title` | The title of the figure. Default: NULL
`point.size` | The size of the point in scatter plot used by `geom_scattermore`. Default: 2.1
`point.alpha` | The alpha value (transparency) of the point in scatter plot used by `geom_scattermore`. Default: 0.6
`line.size` | The size of the fitted line, used by `geom_path`. Default: 0.8
`line.alpha` | The alpha value (transparency) of the fitted line, used by `geom_path`. Default: 0.8
`color.vars` | Optional. A vector of categorical variable of the same length of `theta.v`, and it will be used to color points in figure. Default: NULL
`color.name` | The name of the color variables. Used as the name for legend. Default: NULL
`x_lab` | Title of x-axis. Default: "θ"
`y_lab` | Title of y-axis. Default: "y"
`hue.colors` | The string vector gives custom colors. If not given, the default `scale_color_discrete` will be used. Default: NULL
`...` | Other arguments input to `loess`.

### Details

This function fit a normal loess line, but take the circularity of cell cycle position into account by making `theta.v` 3 periods (`c(theta.v - 2 * pi, theta.v, theta.v + 2 * pi)`) and repeating y 3 times. Only the fitted values corresponding to original `theta.v` will be returned. For convenience, the function will also return a scatter plot with fitted line if needed. Or user can use `pred.df` to visualize the loess line themselves.

### Value

A list with the following elements:

- fitted - The fitted vaues on the loess line. A vector of the length of y.

- residual - The residual values from the fitted loess line, i.e. y - y.fit. A vector of the length of y.

- pred.df - The prediction `data.frame` by uniformly sampling theta from 0 - 2*pi. Names of variables: `x` and `y`. The number of rows equals to `length.out`.

- loess.o - The fitted loess object.

- rsquared - The coefficient of determination R2. Calculated as 1 - residual sum of squares / the total sum of squares.

- fig - When `plot` is `TRUE`, a `ggplot` scatter plot object will be returned with other items.

### Author(s)

Shijie C. Zheng

### See Also

`estimate_cycle_position`, for inferring cell cycle position.

### Examples

    data(neurosphere_example, package = "tricycle")
    neurosphere_example <- estimate_cycle_position(neurosphere_example)
    top2a.idx <- which(rowData(neurosphere_example)$Gene == "Top2a")
    fit.l <- fit_periodic_loess(neurosphere_example$tricyclePosition,
     assay(neurosphere_example, "logcounts")[top2a.idx, ], plot = TRUE)
    fit.l$fig

[Package tricycle version 1.2.1 Index]