R语言99%阈值置信区间是怎么计算的

发布时间:2022-03-19 10:01:37 作者:iii
来源:亿速云 阅读:906

本文小编为大家详细介绍“R语言99%阈值置信区间是怎么计算的”,内容详细,步骤清晰,细节处理妥当,希望这篇“R语言99%阈值置信区间是怎么计算的”文章能帮助大家解决疑惑,下面跟着小编的思路慢慢深入,一起来学习新知识吧。

R语言代码:

###########genotype#############################
genotype<-function(){
count<-0


if (population_structure=="RIL"){
x<-runif(1) 
if (x<=0.5){
count<-1
}else{
count<-0
}

}else{
for(i in 1:2){
x<-runif(1) 
if (x<=0.5){
number<-0.5
}else{
number<-0
}
if(number == 0.5){
count<- count+0.5
}
}
}
return(count)
}
############################################################

###########caluclate of genotype ratio#########################
individuals_genotype<-function(number_of_total_individuals){

ratio_of_genotype<-c()
for(i in 1:number_of_total_individuals){
ratio_of_genotype<-c(ratio_of_genotype,genotype())

}
return(mean(ratio_of_genotype))
}
############################################################

###########SNP_index_caluclation#########################
snp_index<-function(read_depth,ratio_of_genotype_in_the_population){
x1<-rbinom(1,read_depth,ratio_of_genotype_in_the_population)
return(x1/read_depth)
}
############################################################
####################################

####################################
Arg<-commandArgs(TRUE)
###########input###############################################
population_structure<-"F2"
individual_analysis<- c(Arg[1])
reprication<-c(Arg[2])
filter_value<-c(Arg[3])
depth_analysis<-c(1:300)
###########input###############################################



for (key_individual in individual_analysis){
   individual_number<-key_individual
    
    depth_data<-c()
    p_h_data_95<-c()
    p_h_data_99<-c()
    for (key_depth in depth_analysis){
            depth_data<-c(depth_data,key_depth)
            depth<-key_depth
        sum_snp_index<-c()    
        for(i in 1:reprication){    
        ##########gene_frequency######################
ratio_of_genotype_in_the_population<-individuals_genotype(key_individual)
a_snp_index<-snp_index(key_depth,ratio_of_genotype_in_the_population)
if(a_snp_index >= filter_value){
sum_snp_index<-c(sum_snp_index,a_snp_index)
}
##########gene_frequency######################
        }
        order_sum_snp_index<-sort(sum_snp_index)
        length_sum_snp_index<-length(sum_snp_index)
        ##########snp_index_probabirity_0.05######################       
snp_cutoff_up_0.95<-order_sum_snp_index[ceiling(0.95*length_sum_snp_index)]
        p_h_data_95<-c(p_h_data_95,snp_cutoff_up_0.95)   
        ##########snp_index_probabirity_0.05######################
        
        ##########snp_index_probabirity_0.01###################### 
        
        if (ceiling(0.99*length_sum_snp_index)<length_sum_snp_index){
snp_cutoff_up_0.99<-order_sum_snp_index[ceiling(0.99*length_sum_snp_index)]
}else{
snp_cutoff_up_0.99<-order_sum_snp_index[length_sum_snp_index]
}
        p_h_data_99<-c(p_h_data_99,snp_cutoff_up_0.99) 
        ##########snp_index_probabirity_0.01######################      
               
            
     
     
    }
    
        
    FINAL_DATA<-data.frame(DEPTH=depth_data,P_H_95=p_h_data_95,P_H_99=p_h_data_99)
    
    table_name<-paste("./",individual_number,sep="")
    table_name<-paste(table_name,"individuals.txt",sep="")
    write.table(FINAL_DATA,table_name,sep="\t", quote=F, append=F,row.name=F)
    
}

读到这里,这篇“R语言99%阈值置信区间是怎么计算的”文章已经介绍完毕,想要掌握这篇文章的知识点还需要大家自己动手实践使用过才能领会,如果想了解更多相关内容的文章,欢迎关注亿速云行业资讯频道。

推荐阅读:
  1. 什么是r语言
  2. R语言计算移动平均的方法

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

r语言

上一篇:php如何实现指定条件信息数量检索函式

下一篇:php如何实现目录删除函式

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》