R中的代理程序包,无法使其正常工作 [英] proxy package in R, can't make it work

查看:66
本文介绍了R中的代理程序包,无法使其正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在R中实现误差加权的欧式距离函数(与Kumar& Patel.2005类似但不完全相同.Rutcor研究报告.RRR12-2005).我已经知道我想在代理中使用pr_DB来实现此目的.这是我遇到问题的地方.在查看新程序包时,我始终要做的第一件事是将示例剪切并粘贴到R中,以查看它们是否按照我的期望进行操作.这不是在这种情况下发生的事情.我先从一个简单的示例开始,即:

  mydist<-函数(x,y)x * ypr_DB $ set_entry(FUN = mydist,名称= c("test","mydist")) 

好的,到目前为止,很好.我认为,如果要像正常的"dist"类型函数那样工作,我将输入一个非常简单的数据.

 >玩具X Y一个-0.12817993 -1.03238513b 1.56200731 0.93826937c -1.24051847 -1.31005852d -1.12892553 -1.57133401e -1.10098308 0.06577006 

当然,要放一点玩具.SOOOOOO,我尝试以下方法:

  toydist<-dist(toydat,method ="mydist") 

我收到以下消息:

  do.call(.External",c(list(CFUN,x,y,pairwise,if(!is.function(method))get(method)else方法)中的错误:不是标量返回值 

直觉上,我尝试了:

  toydist<-dist(toydat,method ="Euclidean")toydist<-dist(toydat,method ="Manhatten") 

和其他.它们都按预期工作.我以为基本公式必须做一些特殊的事情,才能使它正确地计算距离矩阵.我要计算的是sqrt((x i -x j ) 2 )+(y i -y j ) 2 )+ ...(n i -n j ) 2 )÷sqrt((σx i 2 +σx j 2 )+(σy i 2 +σy j 2 )+ ...(σn i 2 +σn j 2 )),以我的数据集的每个成对组合.

我意识到我可以通过电子表格为单个数据集执行此操作,但是我想进行一些群集自举,我知道如何在R中进行.对于电子表格不实际.

解决方案

现在已经过了必不可少的时间,我可以正式将其关闭.因此,我想到的功能是:

  DistErrAdj<-函数(x,y){sing.err<-sqrt((x ^ 2)+(y ^ 2))总和(sing.err)} 

I am wanting to implement an error-weighted euclidean distance function in R (similar but not quite the same as Kumar & Patel. 2005. Rutcor Research Report. RRR 12-2005). I already know that I want to use pr_DB within proxy for this. Here is where I run into problems. The first thing I always do when looking at a new package is cut-and-paste the examples into R to see if they do what I expect them to do. This is not what happened in this case. I started with the simple included example, to wit:

mydist <- function(x,y) x * y
pr_DB$set_entry(FUN = mydist, names = c("test", "mydist"))

Okay, so far, so good. I figure, if it's going to work just like a normal "dist" type function, I'll toss in a very simple piece of data.

>toydat
        x           y
a -0.12817993 -1.03238513
b  1.56200731  0.93826937
c -1.24051847 -1.31005852
d -1.12892553 -1.57133401
e -1.10098308  0.06577006

Just a little toy set, of course. SOOOOOO, I try out the following:

toydist <- dist(toydat,method="mydist")

I get the following message:

Error in do.call(".External", c(list(CFUN, x, y, pairwise, if (!is.function(method)) get(method) else method),  : 
not a scalar return value

On a hunch, I tried out:

toydist <- dist(toydat,method="Euclidean")
toydist <- dist(toydat,method="Manhatten")

and others. They all work as expected. I am presuming that there is something special that must be done with the basic formula for it to work in a proper manner for computing distance matrices. What I want to compute is sqrt((xi - xj)2) + (yi - yj)2) + ...(ni - nj)2) ÷ sqrt((σxi2 + σxj2) + (σyi2 + σyj2) + ...(σni2 + σnj2)), in every pairwise combination for my data set.

I realize I could do this by spreadsheet for a single data set, but I want to do some clustering bootstrapping, which I know how to do in R. Not practical with a spreadsheet.

解决方案

Now that the requisite time has passed, I can close this out formally. The function I came up with is thus:

DistErrAdj <- function(x,y) {
sing.err <- sqrt((x^2) + (y^2))
sum(sing.err)
}

这篇关于R中的代理程序包,无法使其正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆