measurement <- c(0.704, 0.685, 0.895, 0.377, 0.711, 0.355) #Each position contains the methylation value for BS74, BS71, BS174, BS134, ML15, and BS22, respectively #When a methylation value is not available, its position should be substituted by NaN combinations <- combn(seq(6), 2) # the regression coefficient for each pair of measures x <- list() x[[1]] <- c(-0.23699083, 0.31230647, 0.429878837188) x[[2]] <- c(-0.28109206, 0.21857603, 0.474067456431) x[[3]] <- c(-0.25389859, -0.2362705, 0.750660923371) x[[4]] <- c(-0.17378906, -0.35035923, 0.793634538072) x[[5]] <- c(-0.21169592, -0.16500069, 0.634663208437) x[[6]] <- c( 0.26912685, 0.20000115, 0.157248443428) x[[7]] <- c( 0.27919318, -0.25606219, 0.448793002983) x[[8]] <- c( 0.24637673, -0.3495989, 0.543116236858) x[[9]] <- c( 0.19319181, -0.21946734, 0.427286215609) x[[10]] <- c( 0.23783653, -0.2739245, 0.437915653474) x[[11]] <- c( 0.1568182, -0.35084666, 0.559689788194) x[[12]] <- c( 0.23990307, -0.19578163, 0.344194030962) x[[13]] <- c(-0.11983331, -0.34994783, 0.743168183041) x[[14]] <- c(-0.252382, -0.20448561, 0.67323140595) x[[15]] <- c(-0.31900696, -0.13367664, 0.694656738874) coefficients <- x predictions <- c() # for each pair of measured methylation levels for (i in 1:ncol(combinations)){ # get the current pair curr_combination = combinations[,i] m1 <- measurement[curr_combination[1]] m2 <- measurement[curr_combination[2]] # if one of the level is nan (not measured), ignore it if (is.nan(m1) || is.nan(m2)) next # get the regression coefficient for this pair curr_coefficient = coefficients[[i]] c1 <- curr_coefficient[1] c2 <- curr_coefficient[2] intercept <- curr_coefficient[3] # predict an age curr_prediction <- c1 * m1 + c2 * m2 + intercept predictions <- c(predictions, curr_prediction) } # get the average of all predictionss mean_prediction <- mean(predictions) # and adjust the average by an additional regression final_prediction <- 2.34681774 * mean_prediction - 0.560280844213 print(final_prediction)