美文网首页
2021-06-15

2021-06-15

作者: __method__ | 来源:发表于2021-06-15 13:01 被阅读0次
    plot(x,y)
    # Set seed for fixing 1 simulation
    set.seed(1)
    # Simulate the x values
    # length.out:这个序列的输出长度。
    simx=seq(min(x),max(x),length.out=length(x))
    # Model the y values y=12+ke^(-x), with a starting value of k 
    model = nls(y~12+k*exp(-simx), start=list(k=500))
    summary(model)
    # Add model to scatter plot
    lines(simx,predict(model),lty=2,col="green",lwd=3)
    
    
     随机抽样函数sample()
    
    sample(x,size,replace=FALSE,prob=NULL)
    
    x  随机样本的向量
    
    size  抽取样本的数量
    
    replace  重复抽样与否,FALSE不放回,TRUE(T)放回
    
    prob  等可能事件与否,NULL表示等可能,prob=y,y为和x中各个向量对应的概率
    
    1)52张牌中随机抽4张,不放回、放回
    
    > sample(52,4)
    [1] 40 30 49 25
    > sample(52,4, replace=T)
    [1] 45  9  5  6
    
    2)一枚硬币随机抛10次,正面和反面的随机模拟
    
    > sample(c("Z","F"), 10, replace=T)
     [1] "F" "Z" "F" "Z" "F" "F" "Z" "F" "F" "F"
    > sample(c("Z","F"), 10, replace=T)
     [1] "Z" "F" "F" "Z" "Z" "F" "Z" "F" "Z" "Z"
    
    3)10次手术成功的概率为0.8的随机模拟
    
    > sample(c(0,1), 10, replace=T, prob=c(0.2,0.8))
     [1] 1 1 1 1 0 1 0 1 1 1
    > sample(c(0,1), 10, replace=T, prob=c(0.2,0.8))
     [1] 1 1 1 0 1 1 1 1 1 1
    
    ```![](https://img.haomeiwen.com/i13248401/a28d5737be8afed7.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
    https://www.jianshu.com/p/7d7862c72c4a
    
    二項分佈
    https://blog.csdn.net/csdnxiaobaitiao/article/details/99679679
    
    
    https://blog.csdn.net/weixin_45126863/article/details/99695230
    

    相关文章

      网友评论

          本文标题:2021-06-15

          本文链接:https://www.haomeiwen.com/subject/dhvaeltx.html