全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 R语言论坛
2739 5
2019-08-14
> aggregate(mpg~am,data=mtcars,FUN = function(x) shapiro.test(x))
         am       mpg
1 Automatic 0.9767743
2    Manual 0.9458037
Warning message:
In format.data.frame(if (omit) x[seq_len(n0), , drop = FALSE] else x,  :
  破损的数据框:縮短列的长度或用NA来填充空白

mtcars数据没问题,这个警告是什么意思?

二维码

扫码加我 拉你入群

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

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

全部回复
2019-8-14 13:46:54
shapiro.test 返回的是 htest , 有4个内容,取了第一个显示,要显示p值,应该这样写
复制代码
二维码

扫码加我 拉你入群

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

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

2019-8-15 09:52:36
surfw 发表于 2019-8-14 13:46
shapiro.test 返回的是 htest , 有4个内容,取了第一个显示,要显示p值,应该这样写
我没看明白什么意思。
运行了结果如下:

> head(mtcars)
                   mpg cyl disp  hp drat    wt  qsec vs am gear carb
Mazda RX4         21.0   6  160 110 3.90 2.620 16.46  0  1    4    4
Mazda RX4 Wag     21.0   6  160 110 3.90 2.875 17.02  0  1    4    4
Datsun 710        22.8   4  108  93 3.85 2.320 18.61  1  1    4    1
Hornet 4 Drive    21.4   6  258 110 3.08 3.215 19.44  1  0    3    1
Hornet Sportabout 18.7   8  360 175 3.15 3.440 17.02  0  0    3    2
Valiant           18.1   6  225 105 2.76 3.460 20.22  1  0    3    1
> aggregate(mpg~am,data=mtcars,FUN = function(x) shapiro.test(x)$p.value)
  am       mpg
1  0 0.8987358
2  1 0.5362729
> attach(mtcars)
> shapiro.test(mpg[am==0])

        Shapiro-Wilk normality test

data:  mpg[am == 0]
W = 0.97677, p-value = 0.8987
> aggregate(mpg~am,data=mtcars,FUN = function(x) shapiro.test(x))
  am       mpg
1  0 0.9767743
2  1 0.9458037
Warning message:
In format.data.frame(if (omit) x[seq_len(n0), , drop = FALSE] else x,  :
  破损的数据框:縮短列的长度或用NA来填充空白

另外,请问htest是什么意思?
二维码

扫码加我 拉你入群

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

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

2019-8-15 14:06:36
2.png
二维码

扫码加我 拉你入群

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

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

2019-8-19 16:56:41
surfw 发表于 2019-8-15 14:06
刚看到,感谢!后来我还没懂,捂脸。在你给的线索下,又搜索了下,才懂了你说的意思。
Many tests in R return a htest object. That type of object is basically a list with all the information about the test that has been carried out. All these htest objects contain at least an element statistic with the value of the statistic and an element p.value with the value of the p-value. You can see this easily if you look at the structure of the returned object.

The object returned by shapiro.test()looks like this:

> str(result)
List of 4
$ statistic: Named num 0.933
..- attr(*, "names")= chr "W"
$ p.value : num 7.76e-05
$ method  : chr "Shapiro-Wilk normality test"
$ data.name: chr "beaver2$temp"
- attr(*, "class")= chr "htest"
Because this htest objects are lists, you can use any of the list subsetting methods to extract the information. The following code, for example, extracts the p-value from the t-test on the beaver data:

> t.test(temp ~ activ, data=beaver2)$p.value
[1] 7.269112e-31

二维码

扫码加我 拉你入群

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

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

2022-5-7 23:56:37
surfw 发表于 2019-8-14 13:46
shapiro.test 返回的是 htest , 有4个内容,取了第一个显示,要显示p值,应该这样写
感谢大佬!!!我百度过来的,您拯救了我的作业
二维码

扫码加我 拉你入群

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

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

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群