Skip to contents

Uses a projection approach to calculate factors in new data. Functions in a similar fashion to the predict method of prcomp. The transposed newdata are multiplied by the original loadings matrix.

Usage

# S4 method for class 'FactorisedExperiment,matrix'
projectData(
  object,
  newdata,
  standardise_reduced = TRUE,
  scale_newdata = NULL,
  center_newdata = NULL
)

# S4 method for class 'FactorisedExperiment,data.frame'
projectData(
  object,
  newdata,
  standardise_reduced = TRUE,
  scale_newdata = NULL,
  center_newdata = NULL
)

# S4 method for class 'FactorisedExperiment,SummarizedExperiment'
projectData(
  object,
  newdata,
  standardise_reduced = TRUE,
  scale_newdata = NULL,
  center_newdata = NULL,
  assay_name = "normal"
)

# S4 method for class 'FactorisedExperiment'
predict(object, newdata, ...)

Arguments

object

A FactorisedExperiment object. The loadings slot of this class will be used for projection. Additionally, by default, the scale and center slots are used to apply the original transformation to the new data.

newdata

New data for projection. Must be a data.frame or matrix with features as rows and samples as columns, or a SummarizedExperiment object. Assumes that the rows of newdata match those of the FactorisedExperiment object.

standardise_reduced

Whether or not the reduced data should be standardised (i.e., transformed to have a mean of 0 and standard deviation of 1) after calculation.

scale_newdata

Controls whether the newdata are scaled. If NULL, performs scaling based on the FactorisedExperiment object's scale slot. The value of this argument will be passed to the scale argument of scale.

center_newdata

Controls whether the newdata are centered If NULL, performs centering based on the FactorisedExperiment object's center slot. The value of this argument will be passed to the center argument of scale.

assay_name

If a SummarizedExperiment object is passed as new data, this argument indicates which assay should be used for projection.

...

Additional arguments to be passed to projectData.

Value

Calculates a matrix with samples as rows and factors as columns. If newdata was a matrix or data.frame, this will be returned as a matrix. If a SummarizedExperiment object was passed instead, then a FactorisedExperiment object will be created containing this matrix in its reduced slot.

Details

If scale_newdata and center_newdata are left as NULL, then the projection method assumes that the newdata are on the same scale as the original data of the object. It will therefore use the values of the center and scale slots of the object. For instance, if the scale slot is TRUE, the newdata will be scaled. If the scale slot is a vector, the values of this vector will be applied to scale the newdata.

Author

Jack Gisby

Examples

# Get two random matrices with rnorm
# 1: 100 rows (features) and 20 columns (observations)
X_1 <- ReducedExperiment:::.makeRandomData(100, 20, "feature", "obs")

# Both matrices must have the same features, but they may have different obs
# 2: 100 rows (features) and 30 columns (observations)
X_2 <- ReducedExperiment:::.makeRandomData(100, 30, "feature", "obs")

# Estimate 5 factors based on the data matrix
fe_1 <- estimateFactors(X_1, nc = 5)
fe_1
#> class: FactorisedExperiment 
#> dim: 100 20 5 
#> metadata(0):
#> assays(2): normal transformed
#> rownames(100): feature_1 feature_2 ... feature_99 feature_100
#> rowData names(0):
#> colnames(20): obs_1 obs_2 ... obs_19 obs_20
#> colData names(0):
#> 5 components

# Project the fe_1 factors for the samples in X_2
projected_data <- projectData(fe_1, X_2)
projected_data
#>            factor_1    factor_2    factor_3    factor_4    factor_5
#> obs_1   0.489478464 -0.37522361  0.17907264  0.24298617 -0.82650780
#> obs_2   1.650091796 -1.66195220 -0.60840212 -1.09985491 -1.16535403
#> obs_3   0.161758991 -1.45583706  0.66109597  0.07759218  0.65290376
#> obs_4  -0.011001665 -0.74751310 -1.17334791 -0.30323745 -0.21834571
#> obs_5   1.075736658  0.70784022  0.59278717 -0.93185534  0.13830606
#> obs_6  -0.971740164 -1.22700019  0.17991300  1.12573100  0.74476332
#> obs_7   1.064245782  0.91694633  0.48498311 -0.41442608  0.82311004
#> obs_8  -0.010508632 -0.55777312  0.42665465 -0.07457350 -0.18445205
#> obs_9  -1.376194662  1.08661274 -1.53265291  0.60015056  0.80789276
#> obs_10  0.313645612  1.37758202  0.98975912 -0.40732004  1.49035427
#> obs_11  1.578640794 -0.45548127 -0.97118479  0.56153001 -0.55840758
#> obs_12 -1.971756987 -0.75747554  0.11003474 -0.22978351 -0.67580231
#> obs_13 -1.654405182  0.82659704  0.19532794  0.91884051 -0.23641289
#> obs_14  1.473771729 -0.59066583 -1.76931256  1.82369127 -0.87518093
#> obs_15 -0.956493904 -0.09627737 -0.25344882 -1.84359108  0.01373880
#> obs_16 -1.094796409 -1.43365356 -1.40002566  0.06203495 -1.20866961
#> obs_17  0.410730677  0.60629752  0.33185448  1.10372235  0.74122534
#> obs_18 -0.319911494  0.12666289  0.23467882  0.48212352 -0.79990820
#> obs_19  0.285890000  0.13475692  0.43521336  1.15904823  0.35404071
#> obs_20  0.004543191  1.28523627  1.75893555 -1.97123087 -0.88322033
#> obs_21 -0.813178503  0.35799230  0.14656473 -1.52459315  0.18922329
#> obs_22 -0.912115943  0.25175115  0.65519128 -0.25458440  2.38602532
#> obs_23  0.704597418  2.38892883  1.37168645  0.44096622  0.51992015
#> obs_24 -0.469425889 -1.45061167 -1.50647235  0.14810700  0.16662826
#> obs_25 -0.955120708  0.67701684  1.34135441  1.17272365 -0.23358899
#> obs_26  0.987201959 -1.46123939  1.11715822 -1.46933062  2.53342552
#> obs_27  1.029846610  0.48990792 -1.98852966  1.44558458 -1.26393724
#> obs_28 -0.856005262  0.25110374 -0.06182292  0.69246596 -0.04047724
#> obs_29  1.064572709  0.24713045 -0.82475016 -0.38590739 -0.86289647
#> obs_30  0.077903015  0.53834074  0.87768424 -1.14700983 -1.52839618
#> attr(,"scaled:center")
#>  factor_1  factor_2  factor_3  factor_4  factor_5 
#> -5.335011  4.297722 -3.344957 -1.503321  3.904996 
#> attr(,"scaled:scale")
#>  factor_1  factor_2  factor_3  factor_4  factor_5 
#>  9.993451 12.680630  9.671103 11.169796 10.146132