推理()函数坚持我使用方差分析与双面假设检验; R / RStudio [英] Inference() Function Insisting That I Use ANOVA Versus Two-Sided Hypothesis Test; R/RStudio

查看:554
本文介绍了推理()函数坚持我使用方差分析与双面假设检验; R / RStudio的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用一个名为Inference()的自定义函数,如下面的代码所示。没有该函数的文档,但它来自Coursera中我的DASI类。根据我收到的反馈,我正在使用该功能。我试图在我的类变量和我的单词变量之间进行双侧假设检验,也就是说,在类别低级和工作类别的两种方法之间进行。所以,工人阶级的平均数字 - 低阶级的平均数字。然而,功能/ R / R Studio一直坚持我做一个ANOVA测试。这对我来说不起作用,因为我试图拒绝null,并且在两个独立装置的差异之间创建置信区间。我已经看过这个功能,但由于我不是R专家,我没有看到任何不寻常的东西。

代码:

  load(url(http://bit.ly/dasi_gss_ws_cl))
source(http://bit.ly/dasi_inference)

汇总(gss )
by(gss $ wordsum,gss $ class,mean)
boxplot(gss $ wordsum〜gss $ class)

gss_clean = na.omit(subset(gss,class ==WORKING| class ==LOWER))

推理(y = gss_clean $ wordsum,x = gss_clean $ class,est =mean,type =ht,
null = 0,alternative =twosided,method =theoretical)

返回:

 响应变量:数字,解释变量:分类
错误:使用alternative ='更大'方差分析或卡方检验。
此外:警告消息:
由于方差分析未定义,因此忽略空值。


解决方案

您需要

  gss_clean<  -  droplevels(gss_clean)



<然后你的 inference()调用工作:

 响应变量:数值,解释变量:分类
两个平均值之间的差值
汇总统计:
n_LOWER = 41,mean_LOWER = 5.0732,sd_LOWER = 2.2404
n_WORKING = 407,mean_WORKING = 5.7494,sd_WORKING = 1.8652
平均值之间的差值(下工作)= -0.6762
H0:mu_LOWER - mu_WORKING = 0
HA:mu_LOWER - mu_WORKING!= 0
标准误差= 0.362
测试统计量:Z = -1.868
p-value = 0.0616

问题是除非你放弃未使用的因子水平,否则 inference()的内部机制认为你有一个4级的分类变量,并且它不能做t测试或相当的2类测试:它必须做一个单向ANOVA或模拟。

I'm trying to use a custom function called Inference() as seen in the code below. There's no documentation for the function, but it is from my DASI class in Coursera. According to the feedback I have received, I am using the function properly. I'm trying to do a two-sided hypothesis test between my class variable and my wordsum variable, that is, between the two means of the categories low class and working class. So, the average wordsum for working class - average wordsum for lower class. However, the function/R/R Studio keep insisting I do an ANOVA test. This doesn't work for me since I'm trying to reject the null, and create a confidence interval between the difference of two independent means. I've looked at the function, but as I'm no R expert, I don't see anything out of the ordinary. Any help is greatly appreciated.

Code:

load(url("http://bit.ly/dasi_gss_ws_cl"))
source("http://bit.ly/dasi_inference")

summary(gss)
by(gss$wordsum, gss$class, mean)
boxplot(gss$wordsum ~ gss$class)

gss_clean = na.omit(subset(gss, class == "WORKING" | class =="LOWER"))

inference(y = gss_clean$wordsum, x = gss_clean$class, est = "mean", type = "ht", 
          null = 0, alternative = "twosided", method = "theoretical")

Returns:

Response variable: numerical, Explanatory variable: categorical
Error: Use alternative = 'greater' for ANOVA or chi-square test.
In addition: Warning message:
Ignoring null value since it's undefined for ANOVA.

解决方案

You need

gss_clean <- droplevels(gss_clean)

Then your inference() call works:

Response variable: numerical, Explanatory variable: categorical
Difference between two means
Summary statistics:
n_LOWER = 41, mean_LOWER = 5.0732, sd_LOWER = 2.2404
n_WORKING = 407, mean_WORKING = 5.7494, sd_WORKING = 1.8652
Observed difference between means (LOWER-WORKING) = -0.6762
H0: mu_LOWER - mu_WORKING = 0 
HA: mu_LOWER - mu_WORKING != 0 
Standard error = 0.362 
Test statistic: Z =  -1.868 
p-value =  0.0616 

The problem is that unless you drop the unused levels of the factor, the internal machinery of inference() thinks that you have a 4-level categorical variable, and it can't do a t-test or equivalent 2-category test: it has to do a one-way ANOVA or analogue.

这篇关于推理()函数坚持我使用方差分析与双面假设检验; R / RStudio的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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