楼主: kaikai_nt
2691 5

[问答] 求助! [推广有奖]

  • 0关注
  • 0粉丝

高中生

62%

还不是VIP/贵宾

-

威望
0
论坛币
0 个
通用积分
1.0019
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
148 点
帖子
26
精华
0
在线时间
17 小时
注册时间
2019-7-31
最后登录
2020-1-10

楼主
kaikai_nt 发表于 2019-8-14 12:48:16 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
> 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数据没问题,这个警告是什么意思?

二维码

扫码加我 拉你入群

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

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

关键词:Automatic Aggregate function Message shapiro

回帖推荐

surfw 发表于2楼  查看完整内容

shapiro.test 返回的是 htest , 有4个内容,取了第一个显示,要显示p值,应该这样写

沙发
surfw 发表于 2019-8-14 13:46:54
shapiro.test 返回的是 htest , 有4个内容,取了第一个显示,要显示p值,应该这样写
  1. aggregate(mpg~am,data=mtcars,FUN = function(x) shapiro.test(x)$p.value)
复制代码

藤椅
kaikai_nt 发表于 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是什么意思?

板凳
surfw 发表于 2019-8-15 14:06:36
2.png

报纸
kaikai_nt 发表于 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

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

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

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-21 22:06