我有一个数据框,其中包含对 9 个听众的声音对相似性的判断。我正在尝试运行多维缩放,以便我可以看到绘图上声音之间的多重关系,以及个体差异缩放。我使用
smacof
包。
数据框:https://gist.github.com/al3ka/2b4948d4c13baecae75880dd7f1d5e2c
这是我的代码:
# Get unique voices
voices <- unique(c(results$voice1, results$voice2))
# Number of voices
n_voices <- length(voices)
# Create a list to hold each subject's dissimilarity matrix
dissimilarity_list <- list()
# Create a square dissimilarity matrix for each subject
for (subject_id in unique(results$subject)) {
# Filter responses for the current subject
subject_responses <- results %>% filter(subject == subject_id)
# Initialize an empty matrix
dissimilarity_matrix <- matrix(NA, nrow = n_voices, ncol = n_voices,
dimnames = list(voices, voices))
# Fill the matrix with responses
for (i in 1:nrow(subject_responses)) {
voice1 <- subject_responses$voice1[i]
voice2 <- subject_responses$voice2[i]
response <- subject_responses$response[i]
dissimilarity_matrix[voice1, voice2] <- response
dissimilarity_matrix[voice2, voice1] <- response # Assuming symmetry
}
# Append to the list
dissimilarity_list[[subject_id]] <- dissimilarity_matrix
}
# Convert list of matrices to 3D array
dissimilarity_array <- array(NA, dim = c(n_voices, n_voices, length(dissimilarity_list)))
for (i in 1:length(dissimilarity_list)) {
dissimilarity_array[,,i] <- dissimilarity_list[[i]]
}
# Replace NA values with 0 in the dissimilarity matrices
dissimilarity_array[is.na(dissimilarity_array)] <- 0
# Perform Individual Differences Scaling (INDSCAL)
indscal_result <- smacofIndDiff(dissimilarity_array, ndim = 2)
在我尝试创建数组时,出现错误:
错误:已达到 16.0 Gb 的向量内存限制,请参阅 mem.maxVSize()
尽管我的列表大约有 0.09GB。我有一个全新的 MBair,并且处理过比以前大得多的数据集。我怎样才能解决这个错误?有没有一种方法可以为多个听众运行 MDS,而不为每对声音创建平均分数,因为这会混淆数据中的一些差异?
我曾经在 SPSS 中运行它,没有任何问题,但不知道如何在 R 中的实现中处理多个侦听器而不创建数组,我认为这让我遇到了内存问题。请帮忙!
您的问题是由于使用非常大的数字(主题 ID 是大数字)索引到 dissimilarity_list 引起的,这创建了一个巨大的列表(其中只有 9 个主题),因此后续矩阵将超过 16Gb。 因此,要解决您的问题,请在使用它们构建列表时将您的 subjectID 转换为文本,即
dissimilarity_list[[as.character(subject_id)]] <- dissimilarity_matrix