SAS实现临床试验前动态随机化

2023-11-02 08:59

本文主要是介绍SAS实现临床试验前动态随机化,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

SAS实现临床试验前动态随机化

方法介绍

临床试验前的随机化分组目的在于保证各个试验组间的非研究因素达到均衡。与传统随机化方法相比,动态随机化法的不同之处在于,动态随机化在分配过程中,每一个受试人员进入某一组的概率不会一直保持固定,而是按照前面已入组个体的情况不断地进行变更,从而达到维持所有试验组之间非研究因素达到平衡的目的。每当有新的受试人员进入试验,研究者首先要假设该受试人员进入每一个组的情况,通过统计每组累计的各因素各水平的数目,并乘以一定的权重w(非研究因素间的相对重要性,下面设定为1),来计算不同分配情况下的均衡程度,两相比较后,最后以某一概率(如80%)将受试人员分入某一假设情况下试验组因素间差最小的试验组,以保持良好的均衡性。

假设试验中有N个试验组,M个非处理因素,各因素的水平数分布为LM,Xijk为第i个试验组中因素j水平k的人数(i=1,2,…,N;j=1,2,…,M;k=1,2,…,LM)。受试者入组时,要首先考虑其进入不同试验组后产生的情况。

假设某3因素2水平(2×2×2)的试验需入组一名各因素分别为1,1,2水平(圆括号表示)的受试人员,原有受试人员的累计数量如表1、表2(非圆括号的数字表示两组已入组人员的因素水平的累计情况):

在这里插入图片描述

由表1,表2分别计算出假设新受试个体进入两试验组的情况下,试验组内每个因素的累计水平数即Xijk,再计算表示在与新个体相同因素水平下组1和组2之间的差异Djk值。Pocock和Simon提出了四种计算Djk值的方法,包括极差法、方差法、最大限值法和符号法,其中最常用的是极差法(Djk=|Xi1jk-Xi2jk|)和方差法(Djk=Var(Xi1jk,Xi2jk,…,XiNjk)),这里使用极差法。
假设受试者进入组1时,组1和组2之间的各因素水平差Djk为:
D11=|X111-X211 |=1,
D21=|X121-X221 |=1,
D32=|X111-X232 |=2,
计算总的不均衡值(不妨假设因素重要性相同,权重w全部设定为1),
G1=w1 D11+w2 D21+w3 D32=4.

假设受试者进入组2时,组1和组2之间的各因素水平差Djk为:
D11=|X111-X211 |=3,
D21=|X121-X221 |=1,
D32=|X111-X232 |=4,
计算总的不均衡值(不妨假设因素重要性相同,权重w全部设定为1),
G2=w1 D11+w2 D21+w3 D32=8.
w为各因素的权重,这里全部设为1。由于G1<G2,受试个体进入组1时两组的非研究因素差值较小,表示进入组1时两组的均匀性比进入b组要好,所以设定新的受试者进入组1的概率更高80%)。在实际应用中,若出现G1=G2,优先进入例数少的组,若例数在两组也相等,则进入每组的概率相等。相对于其他的随机化方法,动态随机化综合考量了全部非处理因素的平衡,即使在受试者总人数较少的情况下也能保证良好的均衡性。

SAS9.4代码(八因素(水平不限)动态随机化)

options nodate nonotes nosource;
/*
编号:【ID】001   002  …
因素1:f1
记录日期:date(作为生成随机数的种子数)
因素2:f2
因素3:f3
因素4:f4
因素5:f5
因素6:f6
因素7:f7
因素8:f8
*/
data patient;
input ID $ f1 Date mmddyy10. f2 f3 f4 f5 f6 f7 f8;
cards;
001 1 12-02-2017 1 1 2 1 2 1 1
002 1 01-11-2018 1 2 2 1 2 2 2
003 3 02-05-2018 1 1 1 1 2 1 1
004 1 03-02-2018 1 2 2 1 2 1 1
005	3 04-19-2018 1 2 1 2 1 1 2
006 1 05-08-2018 1 2 2 2 2 1 2
007 1 05-25-2018 1 2 1 2 2 1 1
008 1 06-15-2018 2 1 2 2 2 1 1
009 1 07-13-2018 1 1 2 1 2 2 1
010 1 09-24-2018 1 1 2 2 2 1 2
;
run;
data dataset;
set patient;
i+1;
run;
/*以上是录入数据,最新一行可视作新入组受试个体*//*模拟程序:*/
%let nobs=10;
proc sql;				 /*建立空表*/
create table test
(ID char(8),		/*病人编号*/f1 num(3),f2 num(3),f3 num(3),f4 num(3),f5 num(3),	f6 num(3),f7 num(3),f8 num(3),/*考虑的因素*/date num(10)  ,group_ char(3),	 /*分组*/DiffA num(3),		/*假设新个体纳入A组时,两组在新个体相同水平上的差异*/DiffB num(3),		/*假设新个体纳入B组时,两组在新个体相同水平上的差异*/P num(3)
);
quit;%macro DR(id,f1,f2,f3,f4,f5,f6,f7,f8,date); /*输入编号,非处理因素f1-f8,入组时间*/
proc sql NOPRINT;
insert into test			 /*假设受试个体纳入A组时,A组与新个体在各因素的水平相同的频数*/
set id="&id" ,f1= %sysevalf(&f1+0),f2= %sysevalf(&f2+0),f3= %sysevalf(&f3+0),f4= %sysevalf(&f4+0),f5= %sysevalf(&f5+0),f6= %sysevalf(&f6+0),f7= %sysevalf(&f7+0),f8= %sysevalf(&f8+0),date=%sysevalf(&date+0),group_='A';
select count(f1)  into :AAcount_f1  from test where f1= %sysevalf(&f1) and group_='A';
select count(f2)  into :AAcount_f2  from test where f2= %sysevalf(&f2) and group_='A';
select count(f3)  into :AAcount_f3  from test where f3= %sysevalf(&f3) and group_='A';
select count(f4)  into :AAcount_f4  from test where f4= %sysevalf(&f4) and group_='A';
select count(f5)  into :AAcount_f5  from test where f5= %sysevalf(&f5) and group_='A';
select count(f6)  into :AAcount_f6  from test where f6= %sysevalf(&f6) and group_='A';
select count(f7)  into :AAcount_f7  from test where f7= %sysevalf(&f7) and group_='A';
select count(f8)  into :AAcount_f8  from test where f8= %sysevalf(&f8) and group_='A';/*假设受试个体纳入A组时,B组与新个体在各因素的水平相同的频数*/
select count(f1)  into :ABcount_f1  from test where f1= %sysevalf(&f1) and group_='B';
select count(f2)  into :ABcount_f2  from test where f2= %sysevalf(&f2) and group_='B';
select count(f3)  into :ABcount_f3  from test where f3= %sysevalf(&f3) and group_='B';
select count(f4)  into :ABcount_f4  from test where f4= %sysevalf(&f4) and group_='B';
select count(f5)  into :ABcount_f5  from test where f5= %sysevalf(&f5) and group_='B';
select count(f6)  into :ABcount_f6  from test where f6= %sysevalf(&f6) and group_='B';
select count(f7)  into :ABcount_f7  from test where f7= %sysevalf(&f7) and group_='B';
select count(f8)  into :ABcount_f8  from test where f8= %sysevalf(&f8) and group_='B';update test
set  group_= 'B' where id="&id";  /*假设受试个体纳入B组时,A组与新个体在各因素的水平相同的频数*/
select count(f1)  into :BAcount_f1  from test where f1= %sysevalf(&f1) and group_='A';
select count(f2)  into :BAcount_f2  from test where f2= %sysevalf(&f2) and group_='A';
select count(f3)  into :BAcount_f3  from test where f3= %sysevalf(&f3) and group_='A';
select count(f4)  into :BAcount_f4  from test where f4= %sysevalf(&f4) and group_='A';
select count(f5)  into :BAcount_f5  from test where f5= %sysevalf(&f5) and group_='A';
select count(f6)  into :BAcount_f6  from test where f6= %sysevalf(&f6) and group_='A';
select count(f7)  into :BAcount_f7  from test where f7= %sysevalf(&f7) and group_='A';
select count(f8)  into :BAcount_f8  from test where f8= %sysevalf(&f8) and group_='A';/*假设受试个体纳入B组时,B组与新个体在各因素的水平相同的频数*/
select count(f1)  into :BBcount_f1  from test where f1= %sysevalf(&f1) and group_='B';
select count(f2)  into :BBcount_f2  from test where f2= %sysevalf(&f2) and group_='B';
select count(f3)  into :BBcount_f3  from test where f3= %sysevalf(&f3) and group_='B';
select count(f4)  into :BBcount_f4  from test where f4= %sysevalf(&f4) and group_='B';
select count(f5)  into :BBcount_f5  from test where f5= %sysevalf(&f5) and group_='B';
select count(f6)  into :BBcount_f6  from test where f6= %sysevalf(&f6) and group_='B';
select count(f7)  into :BBcount_f7  from test where f7= %sysevalf(&f7) and group_='B';
select count(f8)  into :BBcount_f8  from test where f8= %sysevalf(&f8) and group_='B';
quit;
proc sql noprint;
select count(*) into :count_A from test where id^="&id" and group_="A";
select count(*) into :count_B from test where id^="&id" and group_="B";
quit;/*在Test数据集中入组对应信息,1对应A,2对应B(对照组)*/
data test;
set test;
format date DDMMYY10.; 
if id="&id"  then 
do;	
count_A=%sysevalf(&count_A+0);	 count_B=%sysevalf(&count_B+0);	
date= %sysevalf(&date);
seed=%sysevalf(&date*&id);/*假设受试个体纳入A组时,A组与新个体在各因素的水平相同的频数总和*/
DiffA=%sysevalf(%sysfunc(abs(&AAcount_f1-&ABcount_f1))+%sysfunc(abs(&AAcount_f2-&ABcount_f2))+%sysfunc(abs(&AAcount_f3-&ABcount_f3))+%sysfunc(abs(&AAcount_f4-&ABcount_f4))+%sysfunc(abs(&AAcount_f5-&ABcount_f5))+%sysfunc(abs(&AAcount_f6-&ABcount_f6))+%sysfunc(abs(&AAcount_f7-&ABcount_f7))+%sysfunc(abs(&AAcount_f8-&ABcount_f8)));
DiffB=%sysevalf(%sysfunc(abs(&BAcount_f1-&BBcount_f1))+%sysfunc(abs(&BAcount_f2-&BBcount_f2))+%sysfunc(abs(&BAcount_f3-&BBcount_f3))+%sysfunc(abs(&BAcount_f4-&BBcount_f4))+%sysfunc(abs(&BAcount_f5-&BBcount_f5))+%sysfunc(abs(&BAcount_f6-&BBcount_f6))+%sysfunc(abs(&BAcount_f7-&BBcount_f7))+%sysfunc(abs(&BAcount_f8-&BBcount_f8)));/*假设受试个体纳入A组时,B组与新个体在各因素的水平相同的频数总和*/if DiffA=DiffB then do;	   /*差异相等时,按相等概率进入A组或B组*/
P=uniform(%sysevalf(&date*&id));	if count_A=count_B then do; 
if P<0.5 then  group_='A' ; else 	group_='B';end;
if 	count_A<count_B	 then do;
if P<0.8 then  group_='A' ; else 	group_='B';end;
if 	count_A>count_B	 then do;
if P<0.8 then  group_='B' ; else 	group_='A';end;
end;if DiffA<DiffB then 		  /*A组差异较小时,按0.8概率进入A组,0.2概率进入B组*/
do; 
P=uniform(%sysevalf(&date*&id));
if P<=0.8 then group_='A' ; else 	group_='B';
end;if DiffA>DiffB then 			 /*B组差异较小时,按0.8概率进入B组,0.2概率进入A组*/
do; 
P=uniform(%sysevalf(&date*&id));
if P<=0.8 then  group_='B' ; else 	group_='A';
end;
end;
run;
%mend;%macro test;
%do	t=1 %to &nobs;
proc sql noprint;
select id,f1,f2,f3,f4,f5,f6,f7,f8,date into :id, :f1,:f2,:f3,:f4,:f5,:f6,:f7,:f8,:date from dataset where i=%sysevalf(&t);
quit;
%let id=&id;                    /*需要在宏test里面用%let赋值转换成局部宏参数,另一种方法用%global声明亦可*/
%let F_1=%sysevalf(&f1); 
%let F_2=%sysevalf(&f2);
%let F_3=%sysevalf(&f3);
%let F_4=%sysevalf(&f4);
%let F_5=%sysevalf(&f5);
%let F_6=%sysevalf(&f6);
%let F_7=%sysevalf(&f7);
%let F_8=%sysevalf(&f8);
%let seed=%sysevalf(&date);
%DR(&id,&f_1,&f_2,&f_3,&f_4,&f_5,&f_6,&f_7,&f_8,&seed);
%end;
run;
%mend;
%test;

sas程序结果如下,work.test数据集中给出了新个体010的分组分组结果,如再有新个体011,在patient数据集中录入新个体各因素数并将全局宏变量nobs赋值为11即可.
在这里插入图片描述

这篇关于SAS实现临床试验前动态随机化的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/329543

相关文章

使用Python和OpenCV库实现实时颜色识别系统

《使用Python和OpenCV库实现实时颜色识别系统》:本文主要介绍使用Python和OpenCV库实现的实时颜色识别系统,这个系统能够通过摄像头捕捉视频流,并在视频中指定区域内识别主要颜色(红... 目录一、引言二、系统概述三、代码解析1. 导入库2. 颜色识别函数3. 主程序循环四、HSV色彩空间详解

PostgreSQL中MVCC 机制的实现

《PostgreSQL中MVCC机制的实现》本文主要介绍了PostgreSQL中MVCC机制的实现,通过多版本数据存储、快照隔离和事务ID管理实现高并发读写,具有一定的参考价值,感兴趣的可以了解一下... 目录一 MVCC 基本原理python1.1 MVCC 核心概念1.2 与传统锁机制对比二 Postg

SpringBoot整合Flowable实现工作流的详细流程

《SpringBoot整合Flowable实现工作流的详细流程》Flowable是一个使用Java编写的轻量级业务流程引擎,Flowable流程引擎可用于部署BPMN2.0流程定义,创建这些流程定义的... 目录1、流程引擎介绍2、创建项目3、画流程图4、开发接口4.1 Java 类梳理4.2 查看流程图4

C++中零拷贝的多种实现方式

《C++中零拷贝的多种实现方式》本文主要介绍了C++中零拷贝的实现示例,旨在在减少数据在内存中的不必要复制,从而提高程序性能、降低内存使用并减少CPU消耗,零拷贝技术通过多种方式实现,下面就来了解一下... 目录一、C++中零拷贝技术的核心概念二、std::string_view 简介三、std::stri

C++高效内存池实现减少动态分配开销的解决方案

《C++高效内存池实现减少动态分配开销的解决方案》C++动态内存分配存在系统调用开销、碎片化和锁竞争等性能问题,内存池通过预分配、分块管理和缓存复用解决这些问题,下面就来了解一下... 目录一、C++内存分配的性能挑战二、内存池技术的核心原理三、主流内存池实现:TCMalloc与Jemalloc1. TCM

OpenCV实现实时颜色检测的示例

《OpenCV实现实时颜色检测的示例》本文主要介绍了OpenCV实现实时颜色检测的示例,通过HSV色彩空间转换和色调范围判断实现红黄绿蓝颜色检测,包含视频捕捉、区域标记、颜色分析等功能,具有一定的参考... 目录一、引言二、系统概述三、代码解析1. 导入库2. 颜色识别函数3. 主程序循环四、HSV色彩空间

Python实现精准提取 PDF中的文本,表格与图片

《Python实现精准提取PDF中的文本,表格与图片》在实际的系统开发中,处理PDF文件不仅限于读取整页文本,还有提取文档中的表格数据,图片或特定区域的内容,下面我们来看看如何使用Python实... 目录安装 python 库提取 PDF 文本内容:获取整页文本与指定区域内容获取页面上的所有文本内容获取

基于Python实现一个Windows Tree命令工具

《基于Python实现一个WindowsTree命令工具》今天想要在Windows平台的CMD命令终端窗口中使用像Linux下的tree命令,打印一下目录结构层级树,然而还真有tree命令,但是发现... 目录引言实现代码使用说明可用选项示例用法功能特点添加到环境变量方法一:创建批处理文件并添加到PATH1

Java使用HttpClient实现图片下载与本地保存功能

《Java使用HttpClient实现图片下载与本地保存功能》在当今数字化时代,网络资源的获取与处理已成为软件开发中的常见需求,其中,图片作为网络上最常见的资源之一,其下载与保存功能在许多应用场景中都... 目录引言一、Apache HttpClient简介二、技术栈与环境准备三、实现图片下载与保存功能1.

canal实现mysql数据同步的详细过程

《canal实现mysql数据同步的详细过程》:本文主要介绍canal实现mysql数据同步的详细过程,本文通过实例图文相结合给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的... 目录1、canal下载2、mysql同步用户创建和授权3、canal admin安装和启动4、canal