相关疑难解决方法(0)

绘制具有不同大小的箱的概率热图/ hexbin

这与另一个问题有关:绘制加权频率矩阵.

我有这个图形(由R中的代码生成): 多重采样

#Set the number of bets and number of trials and % lines
numbet <- 36 
numtri <- 1000 
#Fill a matrix where the rows are the cumulative bets and the columns are the trials
xcum <- matrix(NA, nrow=numbet, ncol=numtri)
for (i in 1:numtri) {
x <- sample(c(0,1), numbet, prob=c(5/6,1/6), replace = TRUE)
xcum[,i] <- cumsum(x)/(1:numbet)
}
#Plot the trials as transparent lines so you can see the build up
matplot(xcum, type="l", xlab="Number of Trials", ylab="Relative Frequency", …
Run Code Online (Sandbox Code Playgroud)

plot r probability heatmap

14
推荐指数
1
解决办法
2835
查看次数

为累积图添加95%置信区间

我想添加一条抛物线,用R表示这个抛硬币图的95%置信限:

x  <- sample(c(-1,1), 60000, replace = TRUE)
plot.ts(cumsum(x), ylim=c(-250,250))
Run Code Online (Sandbox Code Playgroud)

这是我正在寻找的一个例子:图形

更新: @ bill_080的答案非常好.但是我已经计算了10万枚硬币投掷:

str(100ktoss)
num [1:100000] -1 1 1 1 -1 -1 1 -1 -1 -1 ...
Run Code Online (Sandbox Code Playgroud)

而且我真的想在这个情节中添加95%的限制:折腾

plot.ts(cumsum(100ktoss))
Run Code Online (Sandbox Code Playgroud)

花了几个小时来计算我的100K硬币投掷,当我尝试用@ bill_080的代码复制时,我的内存耗尽(100,000).

最后更新:好的.最后一个问题 我有一个几轮累积命中的情节,在一个图表上,每一轮的开始被钳制在零(实际上是1或-1,取决于它是赢还是输).

>str(1.ts)  
Time-Series [1:35] from 1 to 35: 1 2 1 2 3 4 5 4 5 6 ...  
>str(2.ts)  
Time-Series [1:150] from 36 to 185: -1 0 1 0 -1 -2 -1 0 1 2 ...  
Run Code Online (Sandbox Code Playgroud)

我想为每个段添加相同的95%限制,就像这样.现在解决了:

@ bill_080非常感谢.这是最终产品:

附带

plot r sum

6
推荐指数
1
解决办法
1646
查看次数

ggplot中的概率热图

我在一年前问了这个问题并得到了这个"概率热图"的代码: 热图

numbet <- 32
numtri <- 1e5
prob=5/6
#Fill a matrix 
xcum <- matrix(NA, nrow=numtri, ncol=numbet+1)
for (i in 1:numtri) {
x <- sample(c(0,1), numbet, prob=c(prob, 1-prob), replace = TRUE)
xcum[i, ] <- c(i, cumsum(x)/cumsum(1:numbet))
}
colnames(xcum) <- c("trial", paste("bet", 1:numbet, sep=""))

mxcum <- reshape(data.frame(xcum), varying=1+1:numbet, 
idvar="trial", v.names="outcome", direction="long", timevar="bet")


library(plyr)
mxcum2 <- ddply(mxcum, .(bet, outcome), nrow)
mxcum3 <- ddply(mxcum2, .(bet), summarize, 
            ymin=c(0, head(seq_along(V1)/length(V1), -1)), 
            ymax=seq_along(V1)/length(V1),
            fill=(V1/sum(V1)))
head(mxcum3)

library(ggplot2)

p <- ggplot(mxcum3, aes(xmin=bet-0.5, xmax=bet+0.5, ymin=ymin, ymax=ymax)) + 
geom_rect(aes(fill=fill), …
Run Code Online (Sandbox Code Playgroud)

r probability ggplot2

4
推荐指数
1
解决办法
1546
查看次数

重现频率矩阵图

我有一个我想在R中重新创建的情节.这是情节:

频率矩阵

来自:Boring,EG(1941).统计频率为动态均衡.心理学评论,48(4),279.

这略高于我的薪水(能力)因此在这里问.无聊状态:

在第一种情况下,A只能出现'从'(0)或'永远'(1).在第二种情况下,频率为0,1/2或1; 在第三个,1/3,2/3或1等等

显然,您不必担心标签等.只是提示生成数据以及如何绘制将是很好的.;)我不知道如何开始......

plot r frequency matrix

2
推荐指数
2
解决办法
487
查看次数

标签 统计

r ×4

plot ×3

probability ×2

frequency ×1

ggplot2 ×1

heatmap ×1

matrix ×1

sum ×1