This function takes a methylation matrix and a set of weights (provided as a named vector,
a single-column data frame, or a single-column matrix with row names) and returns an object
of class methyl_surro
.
Arguments
- methyl
A matrix of methylation data. All values must be numeric and the matrix must have CpG sites as row names.
- weights
A named numeric vector or a single-column data frame or matrix with CpGs as row names, representing the weights.
- intercept
An optional name of the intercept term within the weights. If provided, the specified intercept will be separated from the weights and stored separately.
Value
An object of class methyl_surro
containing the following components:
- methyl
The input methylation matrix, filtered to include only probes present in the weights, and with additional empty rows added for weights not present in the methylation data.
- weights
A named numeric vector of weights.
- intercept
The numeric value of the intercept, if provided.
NULL
otherwise.
Examples
# Load Methylation Beta Matrix
data(beta_matrix_comp, package = "MethylSurroGetR")
print(beta_matrix_comp)
#> samp1 samp2 samp3 samp4 samp5
#> cg01 0.1028646 0.32037324 0.48290240 0.7205963 0.36948887
#> cg02 0.2875775 0.78830514 0.40897692 0.8830174 0.94046728
#> cg04 0.4348927 0.18769112 0.89035022 0.1422943 0.98421920
#> cg05 0.9849570 0.78229430 0.91443819 0.5492847 0.15420230
#> cg07 0.8998250 0.24608773 0.04205953 0.3279207 0.95450365
#> cg08 0.8895393 0.69280341 0.64050681 0.9942698 0.65570580
#> cg09 0.8930511 0.09359499 0.60873498 0.9540912 0.09104400
#> cg10 0.8864691 0.46677904 0.41068978 0.5854834 0.14190691
#> cg12 0.1750527 0.51150546 0.14709469 0.4045103 0.69000710
#> cg13 0.9630242 0.90229905 0.69070528 0.7954674 0.02461368
#> cg14 0.1306957 0.59998896 0.93529980 0.6478935 0.61925648
#> cg16 0.6531019 0.33282354 0.30122890 0.3198206 0.89139412
#> cg17 0.1428000 0.41454634 0.41372433 0.3688455 0.15244475
#> cg19 0.3435165 0.48861303 0.06072057 0.3077200 0.67299909
#> cg20 0.6567581 0.95447383 0.94772694 0.2197676 0.73707774
# Specify Weights from a Named Vector
data(wts_vec_lin, package = "MethylSurroGetR")
print(wts_vec_lin)
#> cg02 cg03 cg06 cg07 cg08 cg11
#> -0.009083377 -0.001155999 0.005978497 -0.007562015 0.001218960 -0.005869372
#> cg13 cg15 cg17 cg18 Intercept
#> -0.007449367 0.005066157 0.007900907 -0.002510744 1.211000000
# Build the methyl_surro Object
surrogate_vec <- surro_set(methyl = beta_matrix_comp,
weights = wts_vec_lin,
intercept = "Intercept")
print(surrogate_vec)
#> $methyl
#> samp1 samp2 samp3 samp4 samp5
#> cg02 0.2875775 0.7883051 0.40897692 0.8830174 0.94046728
#> cg07 0.8998250 0.2460877 0.04205953 0.3279207 0.95450365
#> cg08 0.8895393 0.6928034 0.64050681 0.9942698 0.65570580
#> cg13 0.9630242 0.9022990 0.69070528 0.7954674 0.02461368
#> cg17 0.1428000 0.4145463 0.41372433 0.3688455 0.15244475
#> cg03 NA NA NA NA NA
#> cg06 NA NA NA NA NA
#> cg11 NA NA NA NA NA
#> cg15 NA NA NA NA NA
#> cg18 NA NA NA NA NA
#>
#> $weights
#> cg02 cg03 cg06 cg07 cg08 cg11
#> -0.009083377 -0.001155999 0.005978497 -0.007562015 0.001218960 -0.005869372
#> cg13 cg15 cg17 cg18
#> -0.007449367 0.005066157 0.007900907 -0.002510744
#>
#> $intercept
#> Intercept
#> 1.211
#>
#> attr(,"class")
#> [1] "methyl_surro"
# Specify Weights from a Data Frame
data(wts_df, package = "MethylSurroGetR")
print(wts_df)
#> wt_lin wt_prb wt_cnt
#> cg02 -0.009083377 0.16511519 0.050895032
#> cg03 -0.001155999 -0.40515934 0.025844226
#> cg06 0.005978497 -0.11603036 0.042036480
#> cg07 -0.007562015 -0.22561636 -0.099875045
#> cg08 0.001218960 0.31464004 -0.004936685
#> cg11 -0.005869372 -0.05148366 -0.055976223
#> cg13 -0.007449367 0.31006435 -0.024036692
#> cg15 0.005066157 0.31238951 0.022554201
#> cg17 0.007900907 0.29434232 -0.029640418
#> cg18 -0.002510744 -0.06016831 -0.077772915
#> Intercept 1.211000000 0.01900000 0.937000000
# Build the methyl_surro Object
surrogate_df <- surro_set(methyl = beta_matrix_comp,
weights = wts_df["wt_lin"],
intercept = "Intercept")
print(surrogate_df)
#> $methyl
#> samp1 samp2 samp3 samp4 samp5
#> cg02 0.2875775 0.7883051 0.40897692 0.8830174 0.94046728
#> cg07 0.8998250 0.2460877 0.04205953 0.3279207 0.95450365
#> cg08 0.8895393 0.6928034 0.64050681 0.9942698 0.65570580
#> cg13 0.9630242 0.9022990 0.69070528 0.7954674 0.02461368
#> cg17 0.1428000 0.4145463 0.41372433 0.3688455 0.15244475
#> cg03 NA NA NA NA NA
#> cg06 NA NA NA NA NA
#> cg11 NA NA NA NA NA
#> cg15 NA NA NA NA NA
#> cg18 NA NA NA NA NA
#>
#> $weights
#> cg02 cg03 cg06 cg07 cg08 cg11
#> -0.009083377 -0.001155999 0.005978497 -0.007562015 0.001218960 -0.005869372
#> cg13 cg15 cg17 cg18
#> -0.007449367 0.005066157 0.007900907 -0.002510744
#>
#> $intercept
#> Intercept
#> 1.211
#>
#> attr(,"class")
#> [1] "methyl_surro"
# Specify Weights from a Matrix
data(wts_mat, package = "MethylSurroGetR")
print(wts_mat)
#> wt_lin wt_prb wt_cnt
#> cg02 -0.009083377 0.16511519 0.050895032
#> cg03 -0.001155999 -0.40515934 0.025844226
#> cg06 0.005978497 -0.11603036 0.042036480
#> cg07 -0.007562015 -0.22561636 -0.099875045
#> cg08 0.001218960 0.31464004 -0.004936685
#> cg11 -0.005869372 -0.05148366 -0.055976223
#> cg13 -0.007449367 0.31006435 -0.024036692
#> cg15 0.005066157 0.31238951 0.022554201
#> cg17 0.007900907 0.29434232 -0.029640418
#> cg18 -0.002510744 -0.06016831 -0.077772915
#> Intercept 1.211000000 0.01900000 0.937000000
# Build the methyl_surro Object
surrogate_mat <- surro_set(methyl = beta_matrix_comp,
weights = wts_mat[, "wt_lin"],
intercept = "Intercept")
print(surrogate_mat)
#> $methyl
#> samp1 samp2 samp3 samp4 samp5
#> cg02 0.2875775 0.7883051 0.40897692 0.8830174 0.94046728
#> cg07 0.8998250 0.2460877 0.04205953 0.3279207 0.95450365
#> cg08 0.8895393 0.6928034 0.64050681 0.9942698 0.65570580
#> cg13 0.9630242 0.9022990 0.69070528 0.7954674 0.02461368
#> cg17 0.1428000 0.4145463 0.41372433 0.3688455 0.15244475
#> cg03 NA NA NA NA NA
#> cg06 NA NA NA NA NA
#> cg11 NA NA NA NA NA
#> cg15 NA NA NA NA NA
#> cg18 NA NA NA NA NA
#>
#> $weights
#> cg02 cg03 cg06 cg07 cg08 cg11
#> -0.009083377 -0.001155999 0.005978497 -0.007562015 0.001218960 -0.005869372
#> cg13 cg15 cg17 cg18
#> -0.007449367 0.005066157 0.007900907 -0.002510744
#>
#> $intercept
#> Intercept
#> 1.211
#>
#> attr(,"class")
#> [1] "methyl_surro"