我想知道如何计算连续频率的对数差异{我的意思是,Log(509)-Log(79),log(2240)-log(509)等}并绘制这些对数差异与间隔中点的关系图在R.
Frequency<-c(7,79,509,2240,2341,623,476,1230,1439,921,448,512,719,673,445,341,310,228,168,14)
Interval<
-c(7-8,8-9,9-10,10-11,11-12,12-13,13-14,14-15,15-16,16-17,17-18,18-19,19-20,20-21,21-22,22-23,23-24,24-25,25-26,26-27)
A<-data.frame(Interval,Frequency)
答案 0 :(得分:0)
Frequency <- c(7,79,509,2240,2341,623,476,1230,1439,921,448,512,719,673,445,341,310,228,168,14)
Interval <- c("7-8","8-9","9-10","10-11","11-12","12-13","13-14","14-15","15-16","16-17","17-18","18-19","19-20","20-21","21-22","22-23","23-24","24-25","25-26","26-27")
# inter <- seq(7.5, 26.5, 1)
inter <- sapply( Interval, function( x ) {
mean(as.numeric(unlist( strsplit( x, "-" ))))
})
freq_e <- diff( log( c( NA, Frequency ), base = exp( 1 ) ) ) # log base e
freq_10 <- diff( log( c( NA, Frequency ), base = 10 ) ) # log base 10
A <- data.frame( Interval = inter,
Frequency_e = freq_e,
Frequency_10 = freq_10,
stringsAsFactors = FALSE)
head( A )
# Interval Frequency_e Frequency_10
# 1 7.5 NA NA
# 2 8.5 2.42353770 1.0525291
# 3 9.5 1.86300016 0.8090907
# 4 10.5 1.48178313 0.6435302
# 5 11.5 0.04410232 0.0191534
# 6 12.5 -1.32378695 -0.5749134
验证
log(79) - log(7)
# [1] 2.423538
log(509) - log(79)
# [1] 1.863
剧情
plot(x = A$Interval, A$Frequency_e )
plot(x = A$Interval, A$Frequency_10 )