R: Fitting a smooth curve through paired (x,y) data
fitXYCurve
R Documentation
Fitting a smooth curve through paired (x,y) data
Description
Fitting a smooth curve through paired (x,y) data.
Usage
## S3 method for class 'matrix'
fitXYCurve(X, weights=NULL, typeOfWeights=c("datapoint"), method=c("loess", "lowess",
"spline", "robustSpline"), bandwidth=NULL, satSignal=2^16 - 1, ...)
Arguments
X
An Nx2 matrix where the columns represent the two channels
to be normalized.
weights
If NULL, non-weighted normalization is done.
If data-point weights are used, this should be a vector of length
N of data point weights used when estimating the normalization
function.
typeOfWeights
A character string specifying the type of
weights given in argument weights.
method
character string specifying which method to use when
fitting the intensity-dependent function.
Supported methods:
"loess" (better than lowess),
"lowess" (classic; supports only zero-one weights),
"spline" (more robust than lowess at lower and upper
intensities; supports only zero-one weights),
"robustSpline" (better than spline).
bandwidth
A double value specifying the bandwidth of the
estimator used.
satSignal
Signals equal to or above this threshold will not
be used in the fitting.
...
Not used.
Value
A named list structure of class XYCurve.
Missing values
The estimation of the function will only be made based on complete
non-saturated observations, i.e. observations that contains no NA
values nor saturated values as defined by satSignal.
Weighted normalization
Each data point, that is, each row in X, which is a
vector of length 2, can be assigned a weight in [0,1] specifying how much
it should affect the fitting of the normalization function.
Weights are given by argument weights, which should be a numericvector of length N.
Note that the lowess and the spline method only support zero-one
{0,1} weights.
For such methods, all weights that are less than a half are set to zero.
Details on loess
For loess, the arguments family="symmetric",
degree=1, span=3/4,
control=loess.control(trace.hat="approximate",
iterations=5, surface="direct") are used.
Author(s)
Henrik Bengtsson
Examples
# Simulate data from the model y <- a + bx + x^c + eps(bx)
x <- rexp(1000)
a <- c(2,15)
b <- c(2,1)
c <- c(1,2)
bx <- outer(b,x)
xc <- t(sapply(c, FUN=function(c) x^c))
eps <- apply(bx, MARGIN=2, FUN=function(x) rnorm(length(x), mean=0, sd=0.1*x))
Y <- a + bx + xc + eps
Y <- t(Y)
lim <- c(0,70)
plot(Y, xlim=lim, ylim=lim)
# Fit principal curve through a subset of (y_1, y_2)
subset <- sample(nrow(Y), size=0.3*nrow(Y))
fit <- fitXYCurve(Y[subset,], bandwidth=0.2)
lines(fit, col="red", lwd=2)
# Backtransform (y_1, y_2) keeping y_1 unchanged
YN <- backtransformXYCurve(Y, fit=fit)
points(YN, col="blue")
abline(a=0, b=1, col="red", lwd=2)
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(aroma.light)
aroma.light v3.2.0 (2016-01-06) successfully loaded. See ?aroma.light for help.
> png(filename="/home/ddbj/snapshot/RGM3/R_BC/result/aroma.light/fitXYCurve.Rd_%03d_medium.png", width=480, height=480)
> ### Name: fitXYCurve
> ### Title: Fitting a smooth curve through paired (x,y) data
> ### Aliases: fitXYCurve fitXYCurve.matrix backtransformXYCurve
> ### backtransformXYCurve.matrix
> ### Keywords: methods
>
> ### ** Examples
>
> # Simulate data from the model y <- a + bx + x^c + eps(bx)
> x <- rexp(1000)
> a <- c(2,15)
> b <- c(2,1)
> c <- c(1,2)
> bx <- outer(b,x)
> xc <- t(sapply(c, FUN=function(c) x^c))
> eps <- apply(bx, MARGIN=2, FUN=function(x) rnorm(length(x), mean=0, sd=0.1*x))
> Y <- a + bx + xc + eps
> Y <- t(Y)
>
> lim <- c(0,70)
> plot(Y, xlim=lim, ylim=lim)
>
> # Fit principal curve through a subset of (y_1, y_2)
> subset <- sample(nrow(Y), size=0.3*nrow(Y))
> fit <- fitXYCurve(Y[subset,], bandwidth=0.2)
>
> lines(fit, col="red", lwd=2)
>
> # Backtransform (y_1, y_2) keeping y_1 unchanged
> YN <- backtransformXYCurve(Y, fit=fit)
> points(YN, col="blue")
> abline(a=0, b=1, col="red", lwd=2)
>
>
>
>
>
>
> dev.off()
null device
1
>