楼主: Harmony.
2589 2

[问答] 急急!!如何用R实现半参数Logistic回归 [推广有奖]

  • 0关注
  • 0粉丝

学前班

40%

还不是VIP/贵宾

-

威望
0
论坛币
0 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
20 点
帖子
1
精华
0
在线时间
0 小时
注册时间
2013-11-24
最后登录
2013-11-24

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
现在有8个变量,在Logistic回归中剔除了4个,剩余4个已经建立Logistic模型。想把剔除的4个变量加回来,作为非线性部分,进行半参数回归,求R实现方法
二维码

扫码加我 拉你入群

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

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

关键词:logistic回归 logistic ogistic logisti logist 半参数 Logistic

沙发
williamshang 发表于 2013-11-24 14:55:36 |只看作者 |坛友微信交流群
好像没什么好说的,希望今天过去比昨天充实吧

使用道具

藤椅
DM小菜鸟 发表于 2015-2-13 23:29:14 |只看作者 |坛友微信交流群
这是用mgcv包配合写的,你看下能不能用
  
mfxboot <- function(modform,dist,data,boot=1000,digits=3){ #dist is the distribution choice of logit or probit
      require(mgcv)

x <- gam(modform, family=binomial(link=dist),method="GCV.Cp",data)
      # get marginal effects

pdf <- ifelse(dist=="probit",               
mean(dnorm(predict(x, type = "link")))            
mean(dlogis(predict(x, type = "link")))
marginal.effects <- pdf*coef(x)


bootvals <- matrix(rep(NA,boot*length(coef(x))), nrow=boot)  
set.seed(1111)  
for(i in 1:boot){   
samp1 <- data[sample(1:dim(data)[1],replace=T,dim(data)[1]),]   
x1 <- gam(modform, family=binomial(link=dist),method="GCV.Cp",samp1)   
pdf1 <- ifelse(dist=="probit",                  
mean(dnorm(predict(x1, type = "link"))),                  
mean(dlogis(predict(x1, type = "link"))))      
bootvals[i,] <- pdf1*coef(x1)     
}

res <- cbind(marginal.effects,apply(bootvals,2,sd),marginal.effects/apply(bootvals,2,sd))     
if(names(x$coefficients[1])=="(Intercept)"){        
res1 <- res[2:nrow(res),]   
res2 <- matrix(as.numeric(sprintf(paste("%.",paste(digits,"f",sep=""),sep=""),res1)),nrow=dim(res1)[1])         
rownames(res2) <- rownames(res1)        
} else {   
res2 <- matrix(as.numeric(sprintf(paste("%.",paste(digits,"f",sep=""),sep="")),nrow=dim(res)[1]))      
rownames(res2) <- rownames(res)   
}     
colnames(res2) <- c("marginal.effect","standard.error","z.ratio")
      return(res2)
}

使用道具

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

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

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

GMT+8, 2024-5-24 03:52