如何计算循环数据的标准偏差
How to calculate standard deviation of circular data
我已按照此处列出的建议计算循环数据的平均值:
https://en.wikipedia.org/wiki/Mean_of_circular_quantities
但我也想计算标准偏差。
#A vector of directional data (separated by 20 degrees each)
Dir2<-c(350,20,40)
#Degrees to Radians
D2R<-0.0174532925
#Radians to Degrees
Rad2<-Dir2 * D2R
Sin2<-sin(Rad2)
SinAvg<-mean(Sin2)
Cos2<-cos(Rad2)
CosAvg<-mean(Cos2)
RADAVG<-atan2(SinAvg, CosAvg)
DirAvg<-RADAVG * R2D
上面给了我平均值,但是我不知道怎么计算SD
我试图只取正弦和余弦的标准偏差的平均值,但我得到了不同的答案。
SinSD<-sd(Sin2)
CosSD<-sd(Cos2)
mean(CosSD, SinSD)
您可以为此使用 circular
软件包:
x <- circular(Rad2)
mean(x)
# Circular Data:
# Type = angles
# Units = radians
# Template = none
# Modulo = asis
# Zero = 0
# Rotation = counter
# [1] 0.2928188 # The same as yours
sd(x)
# [1] 0.3615802
手动,
sqrt(-2 * log(sqrt(sum(Sin2)^2 + sum(Cos2)^2) / length(Rad2)))
# [1] 0.3615802
从sd.circular
.
的源码可以看出
我已按照此处列出的建议计算循环数据的平均值:
https://en.wikipedia.org/wiki/Mean_of_circular_quantities
但我也想计算标准偏差。
#A vector of directional data (separated by 20 degrees each)
Dir2<-c(350,20,40)
#Degrees to Radians
D2R<-0.0174532925
#Radians to Degrees
Rad2<-Dir2 * D2R
Sin2<-sin(Rad2)
SinAvg<-mean(Sin2)
Cos2<-cos(Rad2)
CosAvg<-mean(Cos2)
RADAVG<-atan2(SinAvg, CosAvg)
DirAvg<-RADAVG * R2D
上面给了我平均值,但是我不知道怎么计算SD
我试图只取正弦和余弦的标准偏差的平均值,但我得到了不同的答案。
SinSD<-sd(Sin2)
CosSD<-sd(Cos2)
mean(CosSD, SinSD)
您可以为此使用 circular
软件包:
x <- circular(Rad2)
mean(x)
# Circular Data:
# Type = angles
# Units = radians
# Template = none
# Modulo = asis
# Zero = 0
# Rotation = counter
# [1] 0.2928188 # The same as yours
sd(x)
# [1] 0.3615802
手动,
sqrt(-2 * log(sqrt(sum(Sin2)^2 + sum(Cos2)^2) / length(Rad2)))
# [1] 0.3615802
从sd.circular
.