由于有的表格比较复杂,直接用xtable不好输出,可以先生成csv文件,再用latextablegenerator之类的在线latex表格生成器生成。
数据
三维数组
代码
根据具体的数据进行一些更改即可。
n_list = c(30, 90)
method_list = c(1, 3, 7, 2, 4, 8, 5, 6)
metric_list = c(1, 3, 4:(4+p.x-1), 10)
weight=5
m = 20
gen.table <- function(n_list, method_list, metric_list)
{
tab_dat =NULL
methods_nam = c("SGBESS","SGABESS", "MDSP","Fused Lasso", "Homo", "Indi", "Mixture", "Mixture(fixed)")
metric_nam = c("RPE","rse", "PEE", "NMI1" ,"NMI2", "NMI3", "SG Num1", "SG Num2", "SG Num3", "Run Time")
for(n in n_list)
{
file_name = paste("results/p.x", p.x, "p.z",p.z, "n",n,"m",m, "sigma", sigma,"nrep",nrep, "weight", weight,"one",onelevel, sep="_")
file_name = paste0(file_name, ".rda")
load(file_name)
res = res[method_list, metric_list, ]
mean_dat= format(round(apply(res, c(1, 2), mean), 3) ,nsmall=3)
sd_dat = format(round(apply(res, c(1, 2), sd), 3), nsmall=3)
rownames(mean_dat) = methods_nam[method_list]
colnames(mean_dat) = metric_nam[metric_list]
tab = matrix(paste0(mean_dat, "(", sd_dat, ")"), nrow = nrow(mean_dat), dimnames = dimnames(mean_dat))
tab_dat = rbind(tab_dat, cbind(N=n, tab))
}
return(tab_dat)
}
estimation.preform = tab_dat[, c(1, 2, 3, 7)]
cluster.perform = tab_dat[, -c(1, 2, 3, 7)]
write.csv(estimation.preform, file = "estimate.csv")
write.csv(cluster.perform, file = "cluster.csv")