You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

求助:实现含全处理区组的随机区组设计(Williamson方遇阻)

随机区组设计(Randomised Block Design)构建方案求助

实验需求

  • 3种处理(A、B、C)
  • 3种去叶水平(No、75、81)
  • 9种处理组合,每种设置4次重复,总样本量=9×4=36
  • 布局要求:以3行12列矩阵设置4个区组,每个区组需包含全部9种处理各1次

尝试情况

已尝试使用agricolae、psych包及Williamson方生成代码,但无法完成符合要求的随机化,附尝试代码:

# Define symbols (treatments) 
symbols <- c("CN", "CGP","CV", "KN","KGP","KV","ZN","ZGP","ZV")

# Function to generate a Williamson square 
generate_williamson_square <- function(symbols) 
{ 
  n <- length(symbols) 
  square <- matrix("", nrow = n, ncol = n) 
  for (i in 1:n)
  { 
    for (j in 1:n) { 
      square[i, j] <- symbols[(i + j - 2) %% n + 1] 
    } 
  } 
  return(square) 
} 

# Generate Williamson square 
williamson_square <- generate_williamson_square(symbols)

# Assuming you have already generated the Williamson square 
matrix(williamson_square) 

# Extract the first 4 rows of the Williamson square 
data_set <- williamson_square[1:4, ] 

# Shuffle the columns to create different positions 
matrix_4x9 <- matrix(data = data_set, ncol = 9, nrow = 4) 

symbol_colors <- c("CN" = "darkgreen","CGP" = "lightgreen", "CV" = "green2", 
"KN" = "darkblue", "KGP" = "lightblue", "KV" = "cyan2", "ZN" = "red4", 
"ZGP" = "#FE6F5E","ZV" = "red2") 

# Plot treatments 
plot(0, 0, type = "n", xlab = "Plot", ylab = "Row", xlim = c(0, 9), ylim = c(0, 4), xaxt = "n", yaxt= "n") 
axis(1, at = 1:9, labels = FALSE, tcl = -1.0, line = +0.0) 
axis(2, at = 1:4, labels = FALSE, tcl = -1.0, line = +0.0) 
for (i in 1:ncol(data_set)) { 
  for (j in 1:nrow(data_set)) { 
    text(i - 0.5, j - 0.5, data_set[j, i], cex = 1.2, col = symbol_colors[match(data_set[j, i], symbols)]) 
  } 
} 
# X axis labels 
text(1:6 - 0.5, -0.5, 1:6, xpd = TRUE, adj = 1) 
# Y-axis labels 
for(j in 1:6) { 
  text(-0.35, 6.5 - j, j, xpd = T, adj = 4) # Corrected the indexing here 
} 

# Title 
title("Randomization of Pinot Noir open field") 
# Print the plot 
print() 

目标布局

目标布局示例

现寻求能满足上述全部需求的随机化实现方案。

内容的提问来源于stack exchange,提问作者ZanoniSte

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.23 21:58:12