当前位置: 首页 > news >正文

系统学做网站百度关键词指数查询

系统学做网站,百度关键词指数查询,福安网站定制,沧州网站优化价格加载环境 library("MASS") require(MASS) # Modern Applied Statistics with S,"S"指的是S语言,由贝尔实验室的约翰钱伯斯(John Chambers)等人开发。S语言是R语言的前身,许多R语言的语法和功能都…

加载环境

library("MASS")
require(MASS)
# Modern Applied Statistics with S,"S"指的是S语言,由贝尔实验室的约翰·钱伯斯(John Chambers)等人开发。S语言是R语言的前身,许多R语言的语法和功能都继承自S语言。
library("Matrix")
# Matrix包提供了用于处理稀疏和密集矩阵的函数。它可以高效地执行线性代数操作,比如计算矩阵的逆、求特征值等
# require(compiler)
# 使用require是因为它并不是必需的。如果你不使用compiler包,代码仍然可以正常运行。使用compiler包的目的是为了通过JIT(Just-In-Time)编译来提高代码的执行速度,特别是在处理大量循环或复杂计算时。
# enableJIT(4)
# 这是compiler的函数。这行代码启用JIT编译器,并设置为最高级别(4),即编译所有代码。这可以显著提高代码的执行速度。

计算未截断的检验分数

Non_Trucated_TestScore <- function(X, SampleSize, CorrMatrix) 
{Wi = matrix(SampleSize, nrow = 1);sumW = sqrt(sum(Wi^2));W = Wi / sumW;Sigma = ginv(CorrMatrix);XX = apply(X, 1, function(x) {x1 <- matrix(x, ncol = length(x), nrow = 1); T = W %*% Sigma %*% t(x1);T = (T*T) / (W %*% Sigma %*% t(W));return(T[1,1]);}		);		return(XX);
}
SHom <- cmpfun(Non_Trucated_TestScore);

函数参数:

  • X: 一个矩阵,表示样本数据。X是一个M×K的矩阵,其中M是SNP的数量,K是要组合的汇总统计量的数量。矩阵的每一列包含一个性状的M个SNP的汇总统计量。如果在一个队列中分析了多个性状,每个性状的汇总统计量将放在一列中。矩阵的每一行代表一个SNP。
  • SampleSize: 样本大小。SampleSize是一个长度为M的向量,包含了用于获得K个汇总统计量的M个样本量。当前版本假设不同SNP的样本量是相同的。SampleSize用于在组合汇总统计量时作为权重。
  • CorrMatrix: 相关矩阵。CorrMatrix是X矩阵列之间的相关矩阵,是一个K×K的矩阵,其中K是汇总统计量的数量。。如果X矩阵中没有缺失值,可以通过调用R函数cor(X)来获得CorrMatrix。如果X中有缺失值,可以在删除具有缺失汇总统计量的SNP后以相同方式计算CorrMatrix。对于GWAS数据,这个过程对估计相关矩阵的影响很小。

函数的主要步骤如下:

  1. 计算权重 W,并对其进行归一化。
  2. 计算相关矩阵的广义逆矩阵 Sigma
  3. 对每一行数据 x 进行处理:
    • x 转换为矩阵 x1
    • 计算检验分数 T
  4. 返回每一行数据的检验分数。

用公式来表达:

  1. 计算权重 W
    W = W i ∑ W i 2 W = \frac{Wi}{\sqrt{\sum Wi^2}} W=Wi2 Wi

  2. 计算相关矩阵的广义逆矩阵 Sigma
    Σ = ginv ( CorrMatrix ) \Sigma = \text{ginv}(\text{CorrMatrix}) Σ=ginv(CorrMatrix)

  3. 对每一行数据 x,计算检验分数 T
    x 1 = matrix ( x , ncol = length ( x ) , nrow = 1 ) x1 = \text{matrix}(x, \text{ncol} = \text{length}(x), \text{nrow} = 1) x1=matrix(x,ncol=length(x),nrow=1)
    T = W ⋅ Σ ⋅ x 1 T T = W \cdot \Sigma \cdot x1^T T=WΣx1T
    T = ( T ⋅ T ) W ⋅ Σ ⋅ W T T = \frac{(T \cdot T)}{W \cdot \Sigma \cdot W^T} T=WΣWT(TT)

  4. 返回每一行数据的检验分数 T[1,1]

最终返回所有行的检验分数。

计算截断的检验分数

# X:矩阵,每行表示一个SNP(M),每列表示一个变量(K)
# SampleSize:样本大小向量
# CorrMatrix:相关矩阵
# correct:是否校正权重flag,默认值为1
# startCutoff:截断起始值,默认为0
# endCutoff:截断结束值,默认为1
# CutoffStep:截断步长,默认值为0.05
# isAllpossible:是否使用所有可能的截断值,默认为TRUETrucated_TestScore <- function(X, SampleSize, CorrMatrix, correct = 1, startCutoff = 0, endCutoff = 1, CutoffStep = 0.05, isAllpossible = T) 
{N = dim(X)[2];Wi = matrix(SampleSize, nrow = 1);sumW = sqrt(sum(Wi^2));W = Wi / sumW;	XX = apply(X, 1, function(x) {TTT = -1;if (isAllpossible == T ) {cutoff = sort(unique(abs(x)));	  ## it will filter out any of them. } else {cutoff = seq(startCutoff, endCutoff, CutoffStep);		}for (threshold in cutoff) {x1 = x;index = which(abs(x1) < threshold);if (length(index) == N) break;A = CorrMatrix;W1 = W;	if (length(index) !=0 ) {   x1 = x1[-index];						A  = A[-index, -index];   ## update the matrixW1 = W[-index]; }if (correct == 1){index = which(x1 < 0);if (length(index) != 0) {W1[index] = -W1[index];    ## update the sign}}A = ginv(A);x1 = matrix(x1, nrow = 1); W1 = matrix(W1, nrow = 1);T = W1 %*% A %*% t(x1);T = (T*T) / (W1 %*% A %*% t(W1));if (TTT < T[1,1]) TTT = T[1,1];	}return(TTT);}		);		return(XX);
}
SHet <- cmpfun(Trucated_TestScore);

函数参数:

  • X: 一个矩阵,表示样本数据。
  • SampleSize: 样本大小。
  • CorrMatrix: 相关矩阵。
  • correct: 一个布尔值,默认为1,表示是否需要修正符号。
  • startCutoff: 截断的起始值,默认为0。
  • endCutoff: 截断的结束值,默认为1。
  • CutoffStep: 截断步长,默认为0.05。
  • isAllpossible: 一个布尔值,默认为 T,表示是否使用所有可能的截断值。

函数的主要步骤如下:

  1. 计算权重 W,并对其进行归一化。
  2. 对每一行数据 x 进行处理:
    • 如果 isAllpossibleT,则计算所有可能的截断值 cutoff
    • 否则,生成从 startCutoffendCutoff 的序列作为截断值。
  3. 对每一个截断值 threshold
    • 更新数据 x1 和相关矩阵 A,去除小于 threshold 的元素。
    • 如果 correct 为1,修正符号。
    • 计算截断检验分数 T,并更新最大值 TTT
  4. 返回每一行数据的最大截断检验分数。

用公式来表达:

  1. 计算权重 W
    W = W i ∑ W i 2 W = \frac{Wi}{\sqrt{\sum Wi^2}} W=Wi2 Wi

  2. 对每一行数据 x,计算截断值 cutoff
    cutoff = { sort(unique(abs(x))) if isAllpossible = T seq(startCutoff, endCutoff, CutoffStep) otherwise \text{cutoff} = \begin{cases} \text{sort(unique(abs(x)))} & \text{if } \text{isAllpossible} = T \\ \text{seq(startCutoff, endCutoff, CutoffStep)} & \text{otherwise} \end{cases} cutoff={sort(unique(abs(x)))seq(startCutoff, endCutoff, CutoffStep)if isAllpossible=Totherwise

  3. 对每一个截断值 threshold,更新数据 x1 和相关矩阵 A
    x 1 = x (remove elements where  ∣ x 1 ∣ < threshold ) x1 = x \quad \text{(remove elements where } |x1| < \text{threshold}) x1=x(remove elements where x1∣<threshold)
    A = CorrMatrix (remove corresponding rows and columns) A = \text{CorrMatrix} \quad \text{(remove corresponding rows and columns)} A=CorrMatrix(remove corresponding rows and columns)
    W 1 = W (remove corresponding elements) W1 = W \quad \text{(remove corresponding elements)} W1=W(remove corresponding elements)

  4. 如果 correct 为1,修正符号:
    W 1 [ index ] = − W 1 [ index ] (where  x 1 < 0 ) W1[\text{index}] = -W1[\text{index}] \quad \text{(where } x1 < 0) W1[index]=W1[index](where x1<0)

  5. 计算截断检验分数 T
    A = ginv ( A ) A = \text{ginv}(A) A=ginv(A)
    x 1 = matrix ( x 1 , n r o w = 1 ) x1 = \text{matrix}(x1, nrow = 1) x1=matrix(x1,nrow=1)
    W 1 = matrix ( W 1 , n r o w = 1 ) W1 = \text{matrix}(W1, nrow = 1) W1=matrix(W1,nrow=1)
    T = ( W 1 ⋅ A ⋅ x 1 T ) 2 W 1 ⋅ A ⋅ W 1 T T = \frac{(W1 \cdot A \cdot x1^T)^2}{W1 \cdot A \cdot W1^T} T=W1AW1T(W1Ax1T)2

  6. 返回每一行数据的最大截断检验分数 TTT
    T T T = max ⁡ ( T ) TTT = \max(T) TTT=max(T)

最终返回所有行的最大截断检验分数。

估计Gamma分布的参数

EstimateGamma <- function (N = 1E6, SampleSize, CorrMatrix, correct = 1, startCutoff = 0, endCutoff = 1, CutoffStep = 0.05, isAllpossible = T) {Wi = matrix(SampleSize, nrow = 1);   sumW = sqrt(sum(Wi^2));W = Wi / sumW;Permutation = mvrnorm(n = N, mu = c(rep(0, length(SampleSize))), Sigma = CorrMatrix, tol = 1e-8, empirical = F);Stat =  Trucated_TestScore(X = Permutation, SampleSize = SampleSize, CorrMatrix = CorrMatrix, correct = correct, startCutoff = startCutoff, endCutoff = endCutoff, CutoffStep = CutoffStep, isAllpossible = isAllpossible);a = min(Stat)*3/4ex3 = mean(Stat*Stat*Stat)V =	var(Stat);for (i in 1:100){E = mean(Stat)-a;k = E^2/Vtheta = V/Ea = (-3*k*(k+1)*theta**2+sqrt(9*k**2*(k+1)**2*theta**4-12*k*theta*(k*(k+1)*(k+2)*theta**3-ex3)))/6/k/theta}para = c(k,theta,a);return(para);
}	  

函数参数:

  • N: 生成的样本数量,默认为1E6。
  • SampleSize: 样本大小。
  • CorrMatrix: 相关矩阵。
  • correct: 一个布尔值,默认为1,表示是否需要修正符号。
  • startCutoff: 截断的起始值,默认为0。
  • endCutoff: 截断的结束值,默认为1。
  • CutoffStep: 截断步长,默认为0.05。
  • isAllpossible: 一个布尔值,默认为 T,表示是否使用所有可能的截断值。

函数的主要步骤如下:

  1. 计算权重 W,并对其进行归一化。
  2. 生成 N 个服从多元正态分布的随机样本 Permutation
  3. 使用 Trucated_TestScore 函数计算截断检验分数 Stat
  4. 计算初始参数 aex3V
  5. 通过迭代更新参数 a,并计算Gamma分布的参数 ktheta
  6. 返回参数 kthetaa

用公式来表达:

  1. 计算权重 W
    W = W i ∑ W i 2 W = \frac{Wi}{\sqrt{\sum Wi^2}} W=Wi2 Wi

  2. 生成 N 个服从多元正态分布的随机样本 Permutation
    Permutation = mvrnorm ( n = N , μ = 0 , Σ = CorrMatrix ) \text{Permutation} = \text{mvrnorm}(n = N, \mu = \mathbf{0}, \Sigma = \text{CorrMatrix}) Permutation=mvrnorm(n=N,μ=0,Σ=CorrMatrix)

  3. 使用 Trucated_TestScore 函数计算截断检验分数 Stat
    Stat = Trucated_TestScore ( X = Permutation , SampleSize = SampleSize , CorrMatrix = CorrMatrix , correct = correct , startCutoff = startCutoff , endCutoff = endCutoff , CutoffStep = CutoffStep , isAllpossible = isAllpossible ) \text{Stat} = \text{Trucated\_TestScore}(X = \text{Permutation}, \text{SampleSize} = \text{SampleSize}, \text{CorrMatrix} = \text{CorrMatrix}, \text{correct} = \text{correct}, \text{startCutoff} = \text{startCutoff}, \text{endCutoff} = \text{endCutoff}, \text{CutoffStep} = \text{CutoffStep}, \text{isAllpossible} = \text{isAllpossible}) Stat=Trucated_TestScore(X=Permutation,SampleSize=SampleSize,CorrMatrix=CorrMatrix,correct=correct,startCutoff=startCutoff,endCutoff=endCutoff,CutoffStep=CutoffStep,isAllpossible=isAllpossible)

  4. 计算初始参数 aex3V
    a = 3 4 min ⁡ ( Stat ) a = \frac{3}{4} \min(\text{Stat}) a=43min(Stat)
    ex3 = mean ( Stat 3 ) \text{ex3} = \text{mean}(\text{Stat}^3) ex3=mean(Stat3)
    V = var ( Stat ) V = \text{var}(\text{Stat}) V=var(Stat)

  5. 通过迭代更新参数 a,并计算Gamma分布的参数 ktheta
    for  i in  1 : 100 do \text{for } i \text{ in } 1:100 \text{ do} for i in 1:100 do
    E = mean ( Stat ) − a E = \text{mean}(\text{Stat}) - a E=mean(Stat)a
    k = E 2 V k = \frac{E^2}{V} k=VE2
    θ = V E \theta = \frac{V}{E} θ=EV
    a = − 3 k ( k + 1 ) θ 2 + 9 k 2 ( k + 1 ) 2 θ 4 − 12 k θ ( k ( k + 1 ) ( k + 2 ) θ 3 − ex3 ) 6 k θ a = \frac{-3k(k+1)\theta^2 + \sqrt{9k^2(k+1)^2\theta^4 - 12k\theta(k(k+1)(k+2)\theta^3 - \text{ex3})}}{6k\theta} a=6kθ3k(k+1)θ2+9k2(k+1)2θ412kθ(k(k+1)(k+2)θ3ex3)

  6. 返回参数 kthetaa
    para = ( k , θ , a ) \text{para} = (k, \theta, a) para=(k,θ,a)

最终返回所有行的检验分数。

计算经验分布

# N:模拟次数,默认值为1E6,即100,000
# 其它参数与 Trucated_TestScore 相同EmpDist <- function (N = 1E6, SampleSize, CorrMatrix, correct = 1, startCutoff = 0, endCutoff = 1, CutoffStep = 0.05, isAllpossible = T) {Wi = matrix(SampleSize, nrow = 1);   sumW = sqrt(sum(Wi^2));W = Wi / sumW;Permutation = mvrnorm(n = N, mu = c(rep(0, length(SampleSize))), Sigma = CorrMatrix, tol = 1e-8, empirical = F);Stat =  Trucated_TestScore(X = Permutation, SampleSize = SampleSize, CorrMatrix = CorrMatrix, correct = correct, startCutoff = startCutoff, endCutoff = endCutoff, CutoffStep = CutoffStep, isAllpossible = isAllpossible);return(Stat);
}	

函数参数:

  • N: 生成的样本数量,默认为1,000,000。
  • SampleSize: 样本大小。
  • CorrMatrix: 相关矩阵。
  • correct: 一个布尔值,默认为1,表示是否需要修正符号。
  • startCutoff: 截断的起始值,默认为0。
  • endCutoff: 截断的结束值,默认为1。
  • CutoffStep: 截断步长,默认为0.05。
  • isAllpossible: 一个布尔值,默认为 T,表示是否使用所有可能的截断值。

函数的主要步骤如下:

  1. 计算权重 W,并对其进行归一化。
  2. 使用多元正态分布生成 N 个样本,均值为0,协方差矩阵为 CorrMatrix
  3. 调用 Trucated_TestScore 函数计算截断检验分数。
  4. 返回计算得到的统计量 Stat

用公式来表达:

  1. 计算权重 W
    W = W i ∑ W i 2 W = \frac{Wi}{\sqrt{\sum Wi^2}} W=Wi2 Wi

  2. 使用多元正态分布生成 N 个样本:
    Permutation = mvrnorm ( n = N , μ = 0 , Σ = CorrMatrix ) \text{Permutation} = \text{mvrnorm}(n = N, \mu = \mathbf{0}, \Sigma = \text{CorrMatrix}) Permutation=mvrnorm(n=N,μ=0,Σ=CorrMatrix)

  3. 调用 Trucated_TestScore 函数计算截断检验分数:
    Stat = Trucated_TestScore ( X = Permutation , SampleSize = SampleSize , CorrMatrix = CorrMatrix , correct = correct , startCutoff = startCutoff , endCutoff = endCutoff , CutoffStep = CutoffStep , isAllpossible = isAllpossible ) \text{Stat} = \text{Trucated\_TestScore}(X = \text{Permutation}, \text{SampleSize} = \text{SampleSize}, \text{CorrMatrix} = \text{CorrMatrix}, \text{correct} = \text{correct}, \text{startCutoff} = \text{startCutoff}, \text{endCutoff} = \text{endCutoff}, \text{CutoffStep} = \text{CutoffStep}, \text{isAllpossible} = \text{isAllpossible}) Stat=Trucated_TestScore(X=Permutation,SampleSize=SampleSize,CorrMatrix=CorrMatrix,correct=correct,startCutoff=startCutoff,endCutoff=endCutoff,CutoffStep=CutoffStep,isAllpossible=isAllpossible)

  4. 返回统计量 Stat


文章转载自:
http://pettipants.rmyt.cn
http://feudalism.rmyt.cn
http://articulation.rmyt.cn
http://businesswoman.rmyt.cn
http://sesquioxide.rmyt.cn
http://snobbism.rmyt.cn
http://pulldown.rmyt.cn
http://irradiance.rmyt.cn
http://phantasmic.rmyt.cn
http://coppering.rmyt.cn
http://locomotive.rmyt.cn
http://meatpacking.rmyt.cn
http://attainment.rmyt.cn
http://quadrangular.rmyt.cn
http://fluorocarbon.rmyt.cn
http://futhark.rmyt.cn
http://pontifices.rmyt.cn
http://semicolony.rmyt.cn
http://xanthochroic.rmyt.cn
http://jehad.rmyt.cn
http://epiphytic.rmyt.cn
http://orad.rmyt.cn
http://sprung.rmyt.cn
http://hyperchromic.rmyt.cn
http://roughy.rmyt.cn
http://atomism.rmyt.cn
http://underslung.rmyt.cn
http://retardment.rmyt.cn
http://illusionless.rmyt.cn
http://impious.rmyt.cn
http://don.rmyt.cn
http://dartist.rmyt.cn
http://epizooty.rmyt.cn
http://stenotypist.rmyt.cn
http://color.rmyt.cn
http://congius.rmyt.cn
http://standardize.rmyt.cn
http://includible.rmyt.cn
http://littleneck.rmyt.cn
http://mislay.rmyt.cn
http://idem.rmyt.cn
http://tallowy.rmyt.cn
http://inveiglement.rmyt.cn
http://provisional.rmyt.cn
http://distensile.rmyt.cn
http://acoustician.rmyt.cn
http://garron.rmyt.cn
http://auteur.rmyt.cn
http://tension.rmyt.cn
http://pristine.rmyt.cn
http://succussive.rmyt.cn
http://katalyze.rmyt.cn
http://beerengine.rmyt.cn
http://factionary.rmyt.cn
http://cage.rmyt.cn
http://abut.rmyt.cn
http://generalize.rmyt.cn
http://salable.rmyt.cn
http://obtained.rmyt.cn
http://simulacre.rmyt.cn
http://jun.rmyt.cn
http://inpatient.rmyt.cn
http://aerodonetics.rmyt.cn
http://lemuria.rmyt.cn
http://sfa.rmyt.cn
http://mandola.rmyt.cn
http://subtend.rmyt.cn
http://liederkranz.rmyt.cn
http://multifactor.rmyt.cn
http://wilbur.rmyt.cn
http://tenner.rmyt.cn
http://zapatismo.rmyt.cn
http://drunkometer.rmyt.cn
http://prostomium.rmyt.cn
http://laterality.rmyt.cn
http://countercommercial.rmyt.cn
http://mars.rmyt.cn
http://commiseration.rmyt.cn
http://drugmaker.rmyt.cn
http://ramdac.rmyt.cn
http://prefab.rmyt.cn
http://durion.rmyt.cn
http://serially.rmyt.cn
http://almacantar.rmyt.cn
http://mine.rmyt.cn
http://orlop.rmyt.cn
http://codability.rmyt.cn
http://cystiform.rmyt.cn
http://rayless.rmyt.cn
http://panoptic.rmyt.cn
http://horntail.rmyt.cn
http://autonomic.rmyt.cn
http://immedicable.rmyt.cn
http://overentreat.rmyt.cn
http://recolonize.rmyt.cn
http://inert.rmyt.cn
http://histomorphology.rmyt.cn
http://monosynaptic.rmyt.cn
http://glm.rmyt.cn
http://canalside.rmyt.cn
http://www.dt0577.cn/news/98446.html

相关文章:

  • 杭州滨江网站建设网站统计数据
  • 站群cms系统防恶意竞价点击软件
  • 做网站建设的公司有哪些内容福州百度网站排名优化
  • 做任务的阅币漫画网站东莞网站建设制作
  • 网站建设公司的未来网站自助建站系统
  • java做网站和php做网站网络推广软件哪个好
  • 移动端网站建设的方案培训
  • 个人网站备案名字不同艾滋病多长时间能查出来
  • 中英企业网站源码中公教育培训机构官网
  • b2b网站如何做推广大型网站建站公司
  • 秦皇岛建设规划局百度seo关键词排名优化
  • 梧州网站建设推广无锡百度正规公司
  • asp类似wordpress谷歌seo外包公司哪家好
  • 编程正规学校有哪几所小红书关键词排名优化
  • 设计网站轮廓模板百度搜索引擎优化怎么做
  • 动态网站建设实训目的郑州百度seo网站优化
  • 做网站多少钱特惠西宁君博storrentkitty磁力猫引擎
  • 网站开发参考文献2015年后google中文搜索引擎入口
  • 陕西建设执业中心网站宁波网络营销公司
  • 网站广告位怎么做怎么用网络推广业务
  • 简单网站后台免费发布信息平台有哪些
  • 网站建设都有那些费用搜索引擎优化是什么工作
  • 邢台网站建设免费做网站排名北京seo优化厂家
  • asp.net网站开发与应用免费网络推广渠道
  • wordpress有置顶就置顶没有就其他西安关键词seo公司
  • 新闻聚合网站怎么做房地产最新消息
  • 做网站官网需多少钱seo英文全称
  • 网站设计推荐如何做百度关键词推广
  • 自己做盗版影视网站企业建站模板
  • 宝丰网站建设seo的主要工作内容