Is possible to run NMF on independent variables while considering the dependent variable as a weighting factor. I want to use the dependent variable as a weighting factor.

I have tried the following and get 10 components. But I am not sure whether the dependent variable here dependent_var is used as a weighting factor. My codes are as follows:

library(NMF)

# Read the data into a data frame, where 'dependent_var' is the dependent variable and 'independent_vars' are the independent variables
data <- read.csv("func-conn.csv")

# Extract the dependent variable
dependent_var <- data$y

# Extract the independent variables starting from the second column
independent_vars <- data[, 2:ncol(data)]

# Specify the number of components for NMF
num_components <- 10

# Combine the dependent variable with the independent variables
combined_data <- cbind(dependent_var, independent_vars)

# Perform NMF on the combined data
nmf_model <- nmf(combined_data, num_components, method = "brunet", seed = 2023)

# Get the basis matrix (W) from the NMF model
W <- basis(nmf_model)
H <- coef(nmf_model)


# Get the column names of the independent variables
column_names <- colnames(independent_vars)

# Identify the top components and their corresponding column names
top_components <- 1:num_components
top_component_names <- matrix(NA, nrow = num_components, ncol = 2)

for (i in 1:num_components) {
  component <- W[, i]
  top_features <- order(component, decreasing = TRUE)[1:10]
  top_component_names[i, ] <- c(i, paste(column_names[top_features], collapse = ", "))
}


# Print the top component names
print(top_component_names)```


library(ggplot2)

# Transpose the coefficient matrix H
H <- t(H)

# Calculate the contribution of each component
component_contributions <- colSums(H)

# Create a data frame with the component number and their contributions
component_data <- data.frame(Component = 1:num_components, Contribution = component_contributions)

# Sort the component data frame by Contribution in descending order
sorted_component_data <- component_data[order(-component_data$Contribution), ]

# Create a bar plot of the sorted component contributions
d<-compcont2<-bar_plot_sorted <- ggplot(sorted_component_data, aes(x = reorder(Component, -Contribution), y = Contribution)) +
  geom_bar(stat = "identity", fill = "cadetblue4") +
  xlab("Component") +
  ylab("Contribution") +
  ggtitle("Component Contributions for rsfMRI") +
  theme_minimal()

# Create a line plot of the sorted component contributions
compcont1<-line_plot_sorted <- ggplot(sorted_component_data, aes(x = reorder(Component, -Contribution), y = Contribution)) +
  geom_line() +
  geom_point() +
  xlab("Component") +
  ylab("Contribution") +
  ggtitle("Component Contributions") +
  theme_minimal()

My data (the first 20) look like this: Y is the DV and the rest columns are IV's.

y   GE  rd1 rd2 rd3 rd4 rd5 rd6 rd7 rd8 rd9 rd10    rd11    rd12    rd13    rd14    rd15    rd16    rd17    rd18    rd19    rd20
72  5.087309085 5.371649905 5.346125385 5.740911603 5.762691061 5.607953274 5.589585332 5.546674341 8.542329397 5.64174256  5.542303725 5.534475944 6.107475982 8.430869102 8.405016466 5.92209288  9.169319622 5.413457748 5.443031002 5.76905158  5.460649471
93  8.757116845 7.031945781 6.789027059 7.293864084 6.843699668 7.153977709 6.162761355 6.186505174 6.348475176 7.038878878 7.340856232 7.955361665 6.287215955 6.303828496 5.585135772 7.262920899 7.490600221 5.588830129 6.306189524 5.96846295  6.024281639
92  7.504023904 6.478513822 6.500446724 6.517387844 6.483363466 7.153977709 6.735937377 6.186505174 5.69031891  6.340310719 6.313111943 5.348253965 5.20877612  5.358477115 5.987975871 5.92209288  6.1476247   6.29031965  8.205138273 8.959633506 5.83640425
110 6.028548753 6.201797843 7.654768063 6.517387844 6.843699668 5.917158161 7.309113399 5.546674341 9.200485664 5.874598613 6.570048015 6.838029794 6.6466959   5.831152805 6.995076119 5.92209288  5.811880819 7.342553932 7.859874864 7.364342543 7.903055531
93  5.186703327 8.968957636 5.923286054 6.517387844 5.762691061 10.24602658 5.589585332 5.333397396 5.251548066 8.66887125  5.799239798 6.093141879 5.747996037 5.59481496  5.383715722 5.92209288  5.811880819 9.096277735 9.586191909 9.358456247 5.648526861
87  5.549840053 6.478513822 6.211866389 6.129149723 6.123027263 6.535567935 6.162761355 5.546674341 5.251548066 8.66887125  6.05617587  6.279363858 7.185915817 5.59481496  5.383715722 9.944576937 5.811880819 9.096277735 8.377769978 7.962576654 7.339423364
95  7.340616197 6.478513822 6.500446724 6.905625964 6.843699668 6.844772822 6.735937377 6.186505174 6.348475176 6.806022825 6.313111943 6.651807815 6.6466959   5.358477115 6.995076119 5.92209288  6.1476247   6.46569203  7.341979751 5.96846295  5.648526861
100 7.52761765  6.755229801 7.366187728 8.070340325 6.483363466 9.318411919 7.59570141  7.892720731 7.006631443 7.737447037 6.826984087 7.582917708 5.92773601  8.903544792 6.59223602  7.262920899 6.1476247   6.816436791 6.824084638 5.96846295  6.400036418
108 8.032456749 6.201797843 7.366187728 6.905625964 7.924708274 7.463182596 11.03475755 7.039612953 7.884173131 6.340310719 7.597792304 6.651807815 7.545395762 6.540166341 8.203596417 6.257299885 8.162087981 6.46569203  6.306189524 5.76905158  7.527300753
95  6.343955316 5.925081864 7.943348398 5.740911603 7.564372072 5.917158161 7.309113399 7.039612953 8.542329397 6.107454666 7.854728377 6.093141879 7.006175844 6.303828496 8.002176367 6.257299885 7.826344101 6.29031965  5.960926115 5.76905158  6.587913807
102 5.008490593 5.925081864 5.923286054 5.740911603 6.123027263 5.607953274 5.589585332 5.546674341 5.909704332 5.874598613 5.542303725 5.720697922 6.6466959   5.358477115 5.383715722 5.92209288  5.811880819 7.342553932 6.824084638 6.167874321 5.084894693
95  5.763296056 5.925081864 5.923286054 5.740911603 6.843699668 6.226363048 7.309113399 7.679443786 7.445402287 5.874598613 6.05617587  6.279363858 6.6466959   7.012842031 6.995076119 6.257299885 5.811880819 5.588830129 5.615662706 5.76905158  6.775791196
110 7.176491425 6.478513822 5.346125385 6.517387844 5.762691061 5.607953274 6.735937377 5.333397396 7.006631443 6.107454666 5.799239798 5.720697922 5.747996037 6.540166341 7.397916218 5.92209288  6.1476247   6.641064411 6.824084638 7.563753913 5.83640425
96  7.601345597 7.031945781 6.211866389 6.517387844 6.123027263 6.226363048 6.162761355 5.97322823  8.322943975 6.573166772 6.826984087 4.975810008 7.185915817 7.249179876 6.793656069 6.927713895 7.826344101 5.588830129 7.514611455 5.76905158  5.460649471
61  7.267426009 5.925081864 7.654768063 6.905625964 10.80739789 6.535567935 6.735937377 7.039612953 6.129089754 6.573166772 6.313111943 7.396695729 6.6466959   7.249179876 7.397916218 6.257299885 6.1476247   7.693298693 7.68724316  8.361399395 6.963668585
61  7.177277234 5.925081864 6.211866389 5.740911603 6.123027263 5.917158161 7.022525388 5.97322823  7.006631443 5.874598613 6.05617587  7.210473751 6.107475982 7.012842031 7.397916218 6.59250689  6.1476247   5.939574889 6.651452933 5.76905158  6.212159028
96  6.855910837 6.201797843 5.923286054 6.517387844 5.762691061 6.226363048 6.162761355 8.105997676 6.567860598 6.107454666 5.799239798 6.651807815 6.6466959   7.249179876 6.59223602  5.92209288  7.15485634  6.991809171 6.824084638 5.76905158  5.460649471
106 5.340494786 5.925081864 5.923286054 5.740911603 5.762691061 5.607953274 5.589585332 5.333397396 5.251548066 5.874598613 5.799239798 4.789588029 4.849296175 5.358477115 5.786555821 5.92209288  5.811880819 5.939574889 6.306189524 6.566697061 4.897017304
98  8.320392125 8.138809698 6.789027059 9.623292805 6.843699668 6.535567935 5.876173343 6.399782119 7.226016865 6.806022825 7.340856232 5.720697922 5.388516092 6.776504186 7.196496169 7.262920899 7.826344101 6.29031965  6.13355782  5.96846295  6.587913807

0

There are 0 best solutions below