楼主: jsntxt
22423 15

变数的长度不一样('(weights)') 万分焦急,敬请指教! [推广有奖]

  • 0关注
  • 0粉丝

本科生

62%

还不是VIP/贵宾

-

威望
0
论坛币
255 个
通用积分
0.0600
学术水平
0 点
热心指数
1 点
信用等级
0 点
经验
194 点
帖子
42
精华
0
在线时间
109 小时
注册时间
2008-5-29
最后登录
2015-10-21

相似文件 换一批

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
我通过R软件实现有序结果的logistic回归,程序如下:
library(nnet)
library(MASS)
library(epicalc)
C=rep(c(1,2,3,4),4)
M=c(0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3)
F=c(22,81,30,3,57,236,135,26,11,112,105,17,1,4,10,7)
C<- ordered(C)
m<- polr(C~M,weights=F)
m
ordinal.or.display(m)
单单输入m,是可以显示部分结果的,但是运行ordinal.or.display(m)命令时,R软件报错:
错误于model.frame.default(formula = C ~ M, weights = F) :  变数的长度不一样('(weights)')
我感到十分奇怪,敬请各位大侠指教
二维码

扫码加我 拉你入群

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

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

关键词:weights Weight weigh Eight wei 指教 长度 焦急 weights

回帖推荐

epoh 发表于10楼  查看完整内容

不方便的话, 试试底下epicalc_2.11.1.0.zip 1.移除原来的package “epicalc" 2.From menus\Packages\install package(s) from local zip-files\epicalc_2.11.1.0.zip epicalc_2.11.1.0.zip

epoh 发表于6楼  查看完整内容

library(MASS) library(epicalc) C=rep(c(1,2,3,4),4) M=c(0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3) F=c(22,81,30,3,57,236,135,26,11,112,105,17,1,4,10,7) mydata=data.frame(cbind(C,M,F)) m

epoh 发表于4楼  查看完整内容

这是因为function ordinal.or.display() 有用到function confint() function confint() return A matrix (or vector) 由于你只用一个predicator "M" 所以有错误产生 若你改为 2 predictors m

epoh 发表于2楼  查看完整内容

library(nnet) library(MASS) library(epicalc) C=rep(c(1,2,3,4),4) M=c(0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3) F=c(22,81,30,3,57,236,135,26,11,112,105,17,1,4,10,7) mydata=data.frame(cbind(C,M,F)) mydata$C=ordered(mydata$C) mydata$M=factor(mydata$M) m summary(m) Re-fitting to get Hessian Call: polr(formula = C ~ M, data = mydata, weights = F) Coefficients: Value Std. Error ...

本帖被以下文库推荐

沙发
epoh 发表于 2010-6-29 21:14:37 |只看作者 |坛友微信交流群
library(nnet)
library(MASS)
library(epicalc)
C=rep(c(1,2,3,4),4)
M=c(0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3)
F=c(22,81,30,3,57,236,135,26,11,112,105,17,1,4,10,7)
mydata=data.frame(cbind(C,M,F))
mydata$C=ordered(mydata$C)
mydata$M=factor(mydata$M)
m<- polr(C~M,weights=F,data=mydata)
m
ordinal.or.display(m)
summary(m)
> summary(m)

Re-fitting to get Hessian

Call:
polr(formula = C ~ M, data = mydata, weights = F)

Coefficients:
       Value Std.      Error         t value
M1 0.4797267  0.1899885 2.525031
M2 1.1012361  0.2071994 5.314862
M3 2.5307873  0.4596561 5.505828

Intercepts:
        Value   Std. Error t value
1|2 -1.5741  0.1801    -8.7411
2|3  1.1020  0.1725     6.3874
3|4  3.4674  0.2196    15.7922

Residual Deviance: 1869.092
AIC: 1881.092
已有 1 人评分论坛币 学术水平 热心指数 收起 理由
ruiqwy + 100 + 3 + 5 对论坛有贡献

总评分: 论坛币 + 100  学术水平 + 3  热心指数 + 5   查看全部评分

使用道具

藤椅
jsntxt 发表于 2010-6-29 22:01:24 |只看作者 |坛友微信交流群
结果和我原来的程序不一样啊
有序结果的logistic回归,回归系数应该只有一个啊
library(nnet)
library(MASS)
library(epicalc)
C=rep(c(1,2,3,4),4)
M=c(0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3)
F=c(22,81,30,3,57,236,135,26,11,112,105,17,1,4,10,7)
C<- ordered(C)
m<- polr(C~M,weights=F)
m
library(nnet)
library(MASS)
library(epicalc)
C=rep(c(1,2,3,4),4)
M=c(0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3)
F=c(22,81,30,3,57,236,135,26,11,112,105,17,1,4,10,7)
C<- ordered(C)
m<- polr(C~M,weights=F)
m
Call:
polr(formula = C ~ M, weights = F)

Coefficients:
        M
0.6373681

Intercepts:
      1|2       2|3       3|4
-1.457851  1.225450  3.563591

Residual Deviance: 1873.039
AIC: 1881.039
敬请指教,谢谢!

使用道具

板凳
epoh 发表于 2010-6-30 20:14:17 |只看作者 |坛友微信交流群
这是因为function ordinal.or.display()
有用到function confint()
function confint() return A matrix (or vector)
由于你只用一个predicator "M"
所以有错误产生
若你改为 2 predictors
m<- polr(as.ordered(C)~M+F,data=mydata)
则OK

当然稍修改程序也可运行1 predictor
  Ordinal OR lower95ci upper95ci P value
M 1.891        1.576         2.274         8.38e-12

使用道具

报纸
jsntxt 发表于 2010-7-1 09:06:38 |只看作者 |坛友微信交流群
非常感谢您的解答,我还想请教一下
我这里C代表儿童智力等级,M代表母亲文化程度,F代表频数
通过有序logistic回归,来分析母亲文化程度对儿童智力的影响,因此只有一个predictor
您说稍微修改程序,也可得到如下结果,不知应该如何修改
Ordinal OR lower95ci upper95ci P value
M 1.891        1.576         2.274         8.38e-12
敬请指教,不胜感激!!

使用道具

地板
epoh 发表于 2010-7-1 11:10:15 |只看作者 |坛友微信交流群
library(MASS)
library(epicalc)
C=rep(c(1,2,3,4),4)
M=c(0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3)
F=c(22,81,30,3,57,236,135,26,11,112,105,17,1,4,10,7)
mydata=data.frame(cbind(C,M,F))
m<- polr(as.ordered(C)~M,weights=F,data=mydata)
m
summary(m)
####ordinal.or.display revised
ordinal.or.display1 <- function (ordinal.model, decimal = 3, alpha = 0.05)
{
    model <- ordinal.model
    if (class(model) != "polr")
        stop("The model is not an ordinal logistic regression model")
    s1 <- summary(model)
    t <- s1$coefficients[, 3]
    df <- s1$df.residual
    p.value <- pt(abs(t), df, lower.tail = FALSE)
    coeff <- t(t(model$coefficients))
    coeff.95ci <- cbind(coeff, matrix(confint(model, level = 1 - alpha),dim(coeff)[1],2))
    oor.95ci <- round(exp(coeff.95ci), decimal)
    len.p <- length(p.value)
    k=length(model$zeta)
    oor.95ci <- cbind(oor.95ci, format(p.value[-(len.p:(len.p -(k-1)))], digits = decimal))
    colnames(oor.95ci) <- c("Ordinal OR", paste("lower", 100 -
        100 * alpha, "ci", sep = ""), paste("upper", 100 - 100 *
        alpha, "ci", sep = ""), "P value")
    print.noquote(oor.95ci)
}
ordinal.or.display1(m)
>
  Ordinal OR lower95ci upper95ci P value
M 1.891        1.576         2.274        8.38e-12

##########compare ordinal.or.display() & ordinal.or.display1()
nes96 <- read.table("http://www.stat.washington.edu/quinn/classes/536/data/nes96r.dat", header=TRUE)
polr.out <- polr(as.ordered(ClinLR)~TVnews+selfLR+PID+age+educ+income,data=nes96)
ordinal.or.display(polr.out)
>
Re-fitting to get Hessian
Waiting for profiling to be done...
Re-fitting to get Hessian

       Ordinal OR lower95ci upper95ci P value
TVnews 0.994      0.947     1.043     3.99e-01
selfLR   1.074      0.961     1.201     1.05e-01
PID       0.68        0.631     0.731     3.93e-24
age       0.992      0.984     1            2.25e-02
educ     0.884      0.816     0.959      1.53e-03
income 0.969      0.949     0.99        2.26e-03
Warning message:
In cbind(oor.95ci, format(p.value[-(len.p:(len.p - 1))], digits = decimal)) :
  number of rows of result is not a multiple of vector length (arg 2)

##########
ordinal.or.display1(polr.out)
>
Re-fitting to get Hessian
Waiting for profiling to be done...
Re-fitting to get Hessian

       Ordinal OR lower95ci upper95ci P value
TVnews 0.994      0.947     1.043     3.99e-01
selfLR 1.074         0.961     1.201     1.05e-01
PID      0.68          0.631      0.731     3.93e-24
age      0.992        0.984      1            2.25e-02
educ    0.884        0.816      0.959     1.53e-03
income 0.969       0.949      0.99       2.26e-03

使用道具

7
jsntxt 发表于 2010-7-1 20:11:27 |只看作者 |坛友微信交流群
万分感谢,高手,您太强了,我的QQ438048586,如果方便的话能否加我,不胜感激!!

使用道具

8
jsntxt 发表于 2010-7-1 21:02:12 |只看作者 |坛友微信交流群
为啥要求OR值,需要这么麻烦的程序啊,单单使用ordinal.or.display不能成功?
相反,如果是求出三个系数,正如您在二楼的那种情况,只需要ordinal.or.display这一个命令就搞定了啊?
而且我发现如果用文字形式来表示母亲文化程度(小学,初中,高中,大学)和儿童的智力等级(中下,中等,中上,上等),就可以直接求出三个系数,而且可以直接使用ordinal.or.display这一个命令就搞定了
这其中有何区别啊
敬请指教,QQ 438048586
非常渴望向您多多学习

使用道具

9
jsntxt 发表于 2010-7-2 16:58:41 |只看作者 |坛友微信交流群
等待高手的进一步解惑,不胜感激

使用道具

10
epoh 发表于 2010-7-2 20:46:19 |只看作者 |坛友微信交流群
不方便的话,
试试底下epicalc_2.11.1.0.zip

1.移除原来的package “epicalc"
2.From menus\Packages\install package(s) from

local zip-files\epicalc_2.11.1.0.zip


epicalc_2.11.1.0.zip
epicalc_2.11.1.0.zip (405.23 KB)

使用道具

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

本版微信群
加好友,备注cda
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-5-12 17:49