smooth-IWTomicsData {IWTomics} | R Documentation

## Smooth curves of a `"IWTomicsData"` object

### Description

The function allows to smooth the curves in a `"IWTomicsData"` object, to fill in gaps in the measurements, to change measurement resolutions and, when region alignment is `"scale"`, to measure the features in the different regions on the same grid.

### Usage

    ## S4 method for signature 'IWTomicsData'
    smooth(x, type="locpoly",
      id_regions_subset=idRegions(x), id_features_subset=idFeatures(x),
      resolution_new=resolution(x)[id_features_subset],
      scale_grid=unlist(lapply(lengthFeatures(x)[id_features_subset],
        function(length) max(unlist(length[id_regions_subset])))),
      fill_gaps=TRUE, bandwidth=5, degree=3, dist_knots=10, parallel=FALSE)

### Arguments

`x` | `"IWTomicsData"` object.
`type` | type of smoothing used. Possible types are: `"locpoly"` for local polynomials (see help of `locpoly` function), `"kernel"` for Nadaraya-Watson kernel smoothing with Gaussian kernel (see help of `ksmooth` function), `"splines"` for regression b-splines (see `create.bspline.basis` and `smooth.basis).` Note that `"splines"` is very computational expensive when regions have different length and/or gaps.
`id_regions_subset` | vector with the identifiers of the region datasets to be smoothed.
`id_features_subset` | vector with the identifiers of the features to be smoothed.
`resolution_new` | resolution used to evaluate smoothed curves. As default, measurement resolution is mainteined after smoothing and smoothed curves are evaluated on the same grid as the raw curves. Can be either a constant (the same resolution for all features) or a vector of constants (a resolution for each feature). Not used if region alignment is `"scale"`.
`scale_grid` | number of equally-spaced grid points over which the smoothed curves are evaluated. Can be either a constant (the same grid for all features) or a vector of constants (a grid for each feature). Only used if region alignment is `"scale"`.
`fill_gaps` | if `TRUE` (default), smoothing is used to fill gaps (`NA` measurements). Can be set to `FALSE` only if region alignment is not `"scale"` and measurement resolution is mainteined.
`bandwidth` | bandwidth smoothing parameter used in `"locpoly"` or `"kernel"` type smoothing.
`degree` | degree of local polynomial or b-splines used in `"locpoly"` or `"splines"` type smoothing.
`dist_knots` | (approximate) distance between knots defining the b-splines used in `"splines"` type smoothing.
`parallel` | if `TRUE` smoothing is run in parallel on the different curves.

### Value

`smooth` returns a `"IWTomicsData"` object with smoothed curves and updated resolutions and lengths (without the optional slot `test`).

### Note

If the regions have different lengths and/or gaps are present in the feature measurements (`NA` measurements), `"splines"` type smoothing is very computational expensive. In this case we suggest to use `"locpoly"` or `"kernel"` type smoothing to smooth a large number of curves.

### Author(s)

Marzia A Cremona, Alessia Pini, Francesca Chiaromonte, Simone Vantini

### See Also

`IWTomicsData` for `"IWTomicsData"` class, constructors, accessors and methods; `plot` method to plot `"IWTomicsData"` objects; `IWTomicsTest` for the Interval-Wise Testing.

### Examples

    ## -------------------------------------------------------------------------------------------
    ## -------------------------------------------------------------------------------------------
    ## CURVE ALIGNMENT CENTER
    ## -------------------------------------------------------------------------------------------
    ## -------------------------------------------------------------------------------------------
    data(regionsFeatures_center)
    dev.new()
    plot(regionsFeatures_center,type='curves',N_regions=lengthRegions(regionsFeatures_center))

    ## Smooth all the curves with local polynomials
    regionsFeatures_smooth=smooth(regionsFeatures_center,type='locpoly')
    plot(regionsFeatures_smooth,type='curves',N_regions=lengthRegions(regionsFeatures_smooth))

    ## Smooth only feature 'ftr1', only region datasets 'elem3' and 'control'
    regionsFeatures_smooth=smooth(regionsFeatures_center,type='locpoly',id_features_subset='ftr1',
                                  id_regions_subset=c('elem3','control'))
    plot(regionsFeatures_smooth,type='curves',N_regions=lengthRegions(regionsFeatures_smooth))

    ## Smooth only feature 'ftr1' and change its resolution
    regionsFeatures_smooth=smooth(regionsFeatures_center,type='locpoly',id_features_subset='ftr1',
                                  resolution_new=4000)
    plot(regionsFeatures_smooth,type='curves',N_regions=lengthRegions(regionsFeatures_smooth))

    ## Smooth without filling gaps
    regionsFeatures_smooth=smooth(regionsFeatures_center,type='locpoly',fill_gaps=FALSE)
    plot(regionsFeatures_smooth,type='curves',N_regions=lengthRegions(regionsFeatures_smooth))

    ## -------------------------------------------------------------------------------------------
    ## -------------------------------------------------------------------------------------------
    ## CURVE ALIGNMENT SCALE
    ## -------------------------------------------------------------------------------------------
    ## -------------------------------------------------------------------------------------------
    data(regionsFeatures_scale)
    dev.new()
    plot(regionsFeatures_scale,type='curves',N_regions=lengthRegions(regionsFeatures_scale),
                               average=FALSE,size=FALSE)

    ## Smooth all the curves with local polynomials
    regionsFeatures_smooth=smooth(regionsFeatures_scale,type='locpoly')

    ## Plot of the smoothed curves
    plot(regionsFeatures_smooth,type='curves',N_regions=lengthRegions(regionsFeatures_smooth),
         average=FALSE)

[Package IWTomics version 1.4.0 Index]