wmd(WMDB)
wmd()所属R语言包:WMDB
Discriminant Analysis Methods by Weight Mahalanobis Distance
权重马氏距离判别分析方法
译者:生物统计家园网 机器人LoveR
描述----------Description----------
using Weight Mahalanobis Distance to Discriminant Analysis and return a result table and accuracy report
使用权重马氏距离判别分析,并返回一个结果表,准确度报告
用法----------Usage----------
wmd(TrnX, TrnG, Tweight = NULL, TstX = NULL, var.equal = F)
参数----------Arguments----------
参数:TrnX
matrix or data frame of training set cases.
矩阵或数据框的训练集的情况下。
参数:TrnG
vector of factors of the samples
向量的样品的因素
参数:Tweight
matrix or dataframe of the weight of the parameters,if you do not define the weight,the corresponding percent contributions of the parameters based on the principal component analysis scheme will be used instead
矩阵或数据框的重量的参数,如果你没有定义的权重,相应的百分比贡献度主成分分析计划的基础上的参数将被用来代替
参数:TstX
matrix or data frame of test set cases. A vector will be interpreted as a row vector for a single case.
矩阵或数据框的测试集的情况下。一种向量,将被解释为一个单一的情况下作为一个行向量。
参数:var.equal
whether class have the same covariance or not
是否类具有相同的协方差或不
Details
详细信息----------Details----------
the function of wmd apply two methods,one is normal discriminant analysis and at this time Tweight should be given like diag(rep(w,n)),which w is the weight of each parameter.if Tweight is not given,the the corresponding percent contributions of the parameters based on the principal component analysis scheme will be used instead.
大规模杀伤性武器的功能,适用两种方法,一种是正常的判别和在这个时间Tweight的分析诊断(REP(W,N)),它w是重量每个参数。Tweight的,应给予像没有给出,相应的基于主成分分析方案的参数的百分比贡献度将被使用。
值----------Value----------
result of classifications of test set will be returned. (When TstX is NULL, the function will automatically consider the user is trying to test the Discriminant Analysis Methods by weight Mahalanobis distance. Hence, a test result table and accuracy report will be shown on the R-console.)
测试集的分类结果将被返回。 (当TstX是NULL,该函数会自动考虑用户正试图测试重量马氏距离判别分析方法,因此,测试结果表,准确度报告将显示在R-控制台)。
(作者)----------Author(s)----------
Bingpei Wu
参考文献----------References----------
实例----------Examples----------
##---- Should be DIRECTLY executable !! ----[#----应该是直接的可执行文件! ----]
##-- ==> Define data, use random,[ - ==>定义数据,使用随机的,]
##-- or do help(data=index) for the standard data sets.[# - 帮助(数据=索引)的标准数据集。]
##do not define the weight[没有定义的重量]
X=iris[,1:4]
G=gl(3,50)
wmd(X,G)
##define the weight[#定义的重量]
X=iris[,1:4]
G=gl(3,50)
wmd(X,G,diag(rep(0.25,4)))
## The function is currently defined as[#功能目前被定义为]
function (TrnX, TrnG, Tweight = NULL, TstX = NULL, var.equal = F)
{
if (is.factor(TrnG) == FALSE) {
mx <- nrow(TrnX)
mg <- nrow(TrnG)
TrnX <- rbind(TrnX, TrnG)
TrnG <- factor(rep(1:2, c(mx, mg)))
}
if (is.null(TstX) == TRUE)
TstX <- TrnX
if (is.vector(TstX) == TRUE)
TstX <- t(as.matrix(TstX))
else if (is.matrix(TstX) != TRUE)
TstX <- as.matrix(TstX)
if (is.matrix(TrnX) != TRUE)
TrnX <- as.matrix(TrnX)
if (is.null(Tweight) == TRUE)
Tweight = cor(TstX)
nx <- nrow(TstX)
blong <- matrix(rep(0, nx), nrow = 1, dimnames = list("blong",
1:nx))
g <- length(levels(TrnG))
mu <- matrix(0, nrow = g, ncol = ncol(TrnX))
for (i in 1:g) mu[i, ] <- colMeans(TrnX[TrnG == i, ])
D <- matrix(0, nrow = g, ncol = nx)
if (var.equal == TRUE || var.equal == T) {
for (i in 1:g) D[i, ] <- mahalanobis2(TstX, mu[i, ],
var(TrnX), Tweight)
}
else {
for (i in 1:g) D[i, ] <- mahalanobis2(TstX, mu[i, ],
var(TrnX[TrnG == i, ]), Tweight)
}
for (j in 1:nx) {
dmin <- Inf
for (i in 1:g) if (D[i, j] < dmin) {
dmin <- D[i, j]
blong[j] <- i
}
}
print(blong)
print("num of wrong judgement")
print(which(blong != TrnG))
print("samples divided to")
print(blong[which(blong != TrnG)])
print("samples actually belongs to")
print(TrnG[which(blong != TrnG)])
print("percent of right judgement")
print(1 - length(which(blong != TrnG))/length(blong))
}
转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。
注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
|