R语言-简单回归分析

1、问题

假定有下面的数据,希望对该数据进行回归分析:

IDscore1score2Gender
10111.353210.2male
10212.586540.6male
10319.79380.9female
10412.013520.4female
10511.970810.4female
10617.37480.7female
10714.248840.3female
10818.479720.8male
10918.747920.8male
11018.901460.7male
想做当gender 为male时, summary (score1)
或者是当gender为male时,score1对score2的回归

2、解决

可以用which(也可以用subset):

1、想做当gender 为male时, summary (score1)

>summary(score[which(score$Gender=='male'),'score1'])
注:score为包含楼主示例数据的数据框名。

2、或者是当gender为male时,score1对score2的回归

>score1<-score[which(score$Gender=='male'),'score1']

这是语句2(公式编辑器真是很讨厌,总是弄坏版面,非得用文字隔开):
>score2<-score[which(score$Gender=='male'),'score2']

>score.lm<-lm(score1~score2)

或更简单的:
>score.lm<-lm(score1~score2, data=score[which(score$Gender=='male'),])

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值