0

我正在尝试从 R 中的直方图中提取一些指标。为此,我在 nifti 中有一个图像,并绘制了相应的直方图。之后我想提取平均值、中位数、峰高、峰值和峰宽。为此,我有以下代码:

img = readNIfTI("FA_skeleton_subj_0") #read nifti image
library(HistogramTools)
PlotRelativeFrequency(hist( x = img[ !img==0 ], xlim=c(0,0.8), breaks = seq(0,0.7,0.001)), xlab = "FA", main = "Histogram de FA") #plot relative frequency so I can compare between subjects
mean (img[ !img==0 ]) #!img==0 means that I don't want to count with zero voxels because they are background
median(img[ !img==0])
abline(v=median(img[ !img==0]),col="green")
abline(v=mean(img[ !img==0]),col="blue")

我会感谢一些帮助来计算峰值指标(高度、宽度和值)。谢谢!

4

1 回答 1

0

这是一个随机高斯样本的示例:

x <- rnorm(1000)
h <- hist(x, n=20)
i <- which.max(h$density)
res <- c("Peak value" = mean(h$breaks[i:(i+1)]), 
         "Peak height" = h$density[i], 
         "Peak width" = diff(h$breaks[i:(i+1)]))

此外,您可能想要计算样本的模式,这可以通过modeest包的功能之一来完成:

library(modeest)
m <- asselin(x)
于 2017-09-06T09:06:16.160 回答