基本-T检验->分组因子必须具有准确的2个级别 [英] Basic - T-Test -> Grouping Factor Must have Exactly 2 Levels

查看:1221
本文介绍了基本-T检验->分组因子必须具有准确的2个级别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对R相对较新.对于我的任务,我必须先进行T检验,研究一个政客(保守派或劳动派)的财富对其实际总财富和实际净财富的影响.我必须尝试使用​​简单的t检验来估计在办公室财富中任职的效果.

I am relatively new to R. For my assignment I have to start by conducting a T-Test by looking at the effect of a politician's (Conservative or Labour) wealth on their real gross wealth and real net wealth. I have to attempt to estimate the effect of serving in office wealth using a simple t-test.

数据集称为takehome.dta

The dataset is called takehome.dta

劳动和保守党是二进制的,其中1表示为该政党服务,否则为0.

Labour and Tory are binary where 1 indicates that they serve for that party and 0 otherwise.

财富变量是Inrealgross和Inrealnet.

The variables for wealth are lnrealgross and lnrealnet.

我已经导入并附加了数据集,但是当我尝试进行简单的t检验时.我收到以下消息分组因子必须恰好具有2个级别."不太确定我哪里出了错.任何援助将不胜感激!

I have imported and attached the dataset, but when I attempt to conduct a simple t-test. I get the following message "grouping factor must have exactly 2 levels." Not quite sure where I appear to be going wrong. Any assistance would be appreciated!

推荐答案

您正在这样做吗?

t.test(y~x)

当您打算这样做时

t.test(y,x)

通常使用~,然后您会得到类似

In general use the ~ then you have data like

y <- 1:10
x <- rep(letters[1:2], each = 5)

,,当您拥有类似数据

y <- 1:5
x <- 6:10

我认为您正在做类似的事情:

I assume you're doing something like:

y <- 1:10
x <- rep(1,10)
t.test(y~x) #instead of t.test(y,x)

因为该错误表明您的分组因子x

because the error suggests you have no variation in the grouping factor x

这篇关于基本-T检验-&gt;分组因子必须具有准确的2个级别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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