实验组之间的标准化结果

时间:2019-04-15 05:27:45

标签: sql sql-server

我有五个实验的数据,略有不同,我想找到一种在实验之间标准化结果的方法,以开发出“标准结果”。这是一个我可以乘以每个结果以使其具有可比性的值。 我解决这个问题的方法是,一个以上的实验小组中有个人(假设在一个以上的小组中不会影响结果)。

我假设由于一个实验之间的细微差异,一个以上实验中的个体结果是不同的,因此,通过为每个实验计算一个转换因子,使一个以上实验中的个体结果的平均值相同可以将结果转换为标准结果。

我遇到的问题是在过程结束时,我的大多数转换因子都小于1。但是,我希望得到的偶数个值大约大于1且小于1,因为我有点平均结果。

我的过程和MSQL代码如下:

  1. 按实验和按个人获取数据,并排除仅在1个实验中的所有个人数据。
    SELECT ExperimentID, 
       IndividualID, 
    INTO Z1_IndivByExperiment
    FROM Results
    GROUP BY ExperimentID, 
         IndividualID

    SELECT IndividualID, 
       COUNT(ExperimentID) AS ExperimentCount
    INTO Z2_MultiExperIndiv
    FROM Z1_IndivByExperiment
    GROUP BY IndividualID 
    HAVING COUNT(ExperimentID) > 1
    ORDER BY ExperimentCount DESC
  1. 创建两个表:
    i)每个人(每个实验每个人可以有多个结果)和实验的摘要结果。
    ii)个人总结结果
    SELECT ExperimentID,
       IndividualID, 
       SUM(Results.Result) AS Result_sum, 
       SUM(Results.ResultsCount) AS ResultCount_sum
    INTO Z3_MultiExperIndiv_Results
    FROM Results INNER JOIN
         Z2_MultiExperIndiv ON Results.IndividualID = 
    Z2_MultiExperIndiv.IndividualID
    GROUP BY ExperimentID,
         IndividualID

    SELECT 'Standard' AS Experiment
       IndividualID, 
       SUM(Result_sum) AS ResultIndiv_sum, 
       SUM(ResultCount_sum) AS ResultCountIndiv_sum
    into Z4_MultiExperIndiv_Stand
    FROM Z3_MultiExperIndiv_Results 
    GROUP BY IndividualID
  1. 通过实验分别对表1和表2的结果求和,从而链接在步骤2中创建的两个表。我希望这能为相关实验的个人提供两组结果,并为其他实验中的相关实验的个人提供结果。
    SELECT Z4_MultiExperIndiv_Stand.ExperimentID AS ExperimentID1, 
       Z3_MultiExperIndiv_Results.ExperimentID AS ExperimentID2, 
           SUM(Z4_MultiExperIndiv_Stand.ResultIndiv_sum - 
    Z3_MultiExperIndiv_Results.Result_sum) AS Results1, 
       SUM(Z4_MultiExperIndiv_Stand.ResultCountIndiv_sum - 
    Z3_MultiExperIndiv_Results.ResultCount_sum) AS ResultCount1, 
           SUM(Z3_MultiExperIndiv_Results.Result_sum) AS Results 2, 
       SUM(Z3_MultiExperIndiv_Results.ResultCount_sum) AS ResultCount2
    into Z5_StandardConversion_data
    FROM Z3_MultiExperIndiv_Results INNER JOIN
         Z4_MultiExperIndiv_Stand ON Z3_MultiExperIndiv_Results.IndividualID = 
    Z4_MultiExperIndiv_Stand.IndividualID
    GROUP BY Z4_MultiExperIndiv_Stand.IndividualId,
         Z3_MultiExperIndiv_Results.IndividualId
  1. 然后,我将每个结果集的结果除以结果数,然后彼此除以得到每个实验的标准数。
    SELECT ExperimentID1, 
       ExperimentID2, 
       Results1, 
       ResultCount1, 
       Results2, 
       ResultCount2, 
       Results1 / ResultCount1 AS Result1_avg, 
       Results2 / ResultCount2 AS Result2_avg, 
    (ResultCount2 * Results1) / (ResultCount1 * Results2) AS Conversion
    FROM Z5_StandardConversion_data

样本输入数据:

enter image description here

样本输出:

enter image description here

0 个答案:

没有答案