楼主: Will2011
5869 15

[问答] R里能否像Splus一样计算empirical copula? [推广有奖]

  • 0关注
  • 1粉丝

本科生

46%

还不是VIP/贵宾

-

威望
0
论坛币
674 个
通用积分
0.0412
学术水平
0 点
热心指数
2 点
信用等级
0 点
经验
845 点
帖子
56
精华
0
在线时间
79 小时
注册时间
2011-1-23
最后登录
2011-9-3

楼主
Will2011 发表于 2011-8-3 00:08:12 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
在Splus里有专门的empirical.copula指令,请问一下R里有相对应的吗?算出empirical cdf后发现R里没有empirical.copula这个指令。。。
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:Empirical Copula opula PLUS MPI

沙发
情迷仲夏夜 发表于 2011-8-3 01:37:55

藤椅
Will2011 发表于 2011-8-3 01:45:28
情迷仲夏夜 发表于 2011-8-3 01:37
http://www.jstatsoft.org/v21/i04/paper
https://stat.ethz.ch/pipermail/r-help/2007-July/135725.html
...
请问一下splus中是否没有像R中那样能够简便求出empirical cdf(ecdf)的命令?

板凳
情迷仲夏夜 发表于 2011-8-3 02:29:24

报纸
Will2011 发表于 2011-8-3 11:02:15
情迷仲夏夜 发表于 2011-8-3 02:29
http://www.solutionmetrics.com.au/support/Demos/EnvironmentalStats/envirodemo.html
这个貌似只能画出来,我是想求出empirical cdf然后用copula连接起来~不知道您能不能帮我再找找~麻烦您拉~十分感谢~

地板
情迷仲夏夜 发表于 2011-8-4 01:34:41
How can I calculate an emperical CDF in R?
http://stackoverflow.com/questio ... -emperical-cdf-in-r
I'm reading a sparse table from a file which looks like:
1 0 7 0 0 1 0 0 0 5 0 0 0 0 2 0 0 0 0 1 0 0 0 1
1 0 0 1 0 0 0 3 0 0 0 0 1 0 0 0 1
0 0 0 1 0 0 0 2 0 0 0 0 1 0 0 0 1 0 1 0 0 1
1 0 0 1  0 3 0 0 0 0 1 0 0 0 1
0 0 0 1 0 0 0 2 0 0 0 0 1 0 0 0 1 0 1 0 0 1 1 2 1 0 1 0 1
Note row lengths are different.
Each row represents a single simulation. The value in the i-th column in each row says how many times value i-1 was observed in this simulation. For example, in the first simulation (first row), we got a single result with value '0' (first column), 7 results with value '2' (third column) etc.
I wish to create an average cumulative distribution function (CDF) for all the simulation results, so I could later use it to calculate an empirical p-value for true results.
To do this I can first sum up each column, but I need to take zeros for the undef columns.
How do I read such a table with different row lengths? How do I sum up columns replacing 'undef' values with 0'? And finally, how do I create the CDF? (I can do this manually but I guess there is some package which can do that).
Answers:
This will read the data in:
dat <- textConnection("1 0 7 0 0 1 0 0 0 5 0 0 0 0 2 0 0 0 0 1 0 0 0 1
1 0 0 1 0 0 0 3 0 0 0 0 1 0 0 0 1
0 0 0 1 0 0 0 2 0 0 0 0 1 0 0 0 1 0 1 0 0 1
1 0 0 1  0 3 0 0 0 0 1 0 0 0 1
0 0 0 1 0 0 0 2 0 0 0 0 1 0 0 0 1 0 1 0 0 1 1 2 1 0 1 0 1")
df <- data.frame(scan(dat, fill = TRUE, what = as.list(rep(1, 29))))
names(df) <- paste("Val", 1:29)
close(dat)
Resulting in:
> head(df)
  Val 1 Val 2 Val 3 Val 4 Val 5 Val 6 Val 7 Val 8 Val 9 Val 10 Val 11 Val 12
1     1     0     7     0     0     1     0     0     0      5      0      0
2     1     0     0     1     0     0     0     3     0      0      0      0
3     0     0     0     1     0     0     0     2     0      0      0      0
4     1     0     0     1     0     3     0     0     0      0      1      0
5     0     0     0     1     0     0     0     2     0      0      0      0
....

If the data are in a file, provide the file name instead of dat. This code presumes that there are a maximum of 29 columns, as per the data you supplied. Alter the 29 to suit the real data.

We get the column sums using
df.csum <- colSums(df, na.rm = TRUE)

the ecdf() function generates the ECDF you wanted,

df.ecdf <- ecdf(df.csum)

and we can plot it using the plot() method:

plot(df.ecdf, verticals = TRUE)

7
Will2011 发表于 2011-8-4 03:22:48
情迷仲夏夜 发表于 2011-8-4 01:34
How can I calculate an emperical CDF in R?
http://stackoverflow.com/questio ... -emperical-cdf-in-r ...
非常感谢你给予的帮助!非常感谢!
我现在的问题比较纠结,我想先求出两组数据的empirical cdf,然后用empirical copula把他们连接起来,可是splus中有empirical.copula但是没有ecdf,而R中有ecdf却没有empirical.copula。。该怎么解决啊?

8
情迷仲夏夜 发表于 2011-8-5 03:35:37
既然你说:“splus中有empirical.copula但是没有ecdf,而R中有ecdf却没有empirical.copula”,那么,因为R是源程序开放系统,当你在R中只执行ecdf时,R就会自己打印出源程序:
function (x)
{
    x <- sort(x)
    n <- length(x)
    if (n < 1)
        stop("'x' must have 1 or more non-missing values")
    vals <- unique(x)
    rval <- approxfun(vals, cumsum(tabulate(match(x, vals)))/n,
        method = "constant", yleft = 0, yright = 1, f = 0, ties = "ordered")
    class(rval) <- c("ecdf", "stepfun", class(rval))
    attr(rval, "call") <- sys.call()
    rval
}
那么,你可不可以将R产生的上面这个源程序,写入到SPlus来做为为你自己的需要量体打造的一个功能,在Splus里来实现你想要计算ecdf的可能性,去分别算出你想要算的那两组数据?然后,再用SPlus里的empirical.copula把算得的这两部分连接起来?
已有 1 人评分学术水平 热心指数 信用等级 收起 理由
Will2011 + 1 + 1 + 1 非常感谢!

总评分: 学术水平 + 1  热心指数 + 1  信用等级 + 1   查看全部评分

9
Will2011 发表于 2011-8-5 03:50:47
情迷仲夏夜 发表于 2011-8-5 03:35
既然你说:“splus中有empirical.copula但是没有ecdf,而R中有ecdf却没有empirical.copula”,那么,因为R是 ...
非常感谢您的帮助,不过貌似这样输入到Splus好像不起作用。我又新寻找的其它方法来做empirical copula,但也是遇到了一些问题,我也在论坛里寻求帮助了,您也帮我看看有什么办法可以解决,真的十分感谢!

10
情迷仲夏夜 发表于 2011-8-5 05:04:36
R是可以写自己的function(),难道SPlus不允许写自己的function()?

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-1-9 05:18