【问题标题】:Checking for normality distribution error检查正态分布错误
【发布时间】:2021-06-01 00:10:51
【问题描述】:

我想检查我的数据是否正常,但是当我这样计算时收到一条错误消息。

library(tidyverse)

df <- read.table(header=TRUE, text="
ID System Maneuver value  
1 A E 3
1 A R 2  
1 B E NA  
1 B R NA 
2 A E 3
2 A R 2   
2 B E NA 
2 B R NA 
3 A E 2
3 A R 6  
3 B E NA
3 B R NA
4 A E NA
4 A R NA  
4 B E 5  
4 B R 3 
5 A E NA
5 A R NA   
5 B E 6 
5 B R 6 
6 A E NA
6 A R NA  
6 B E 4
6 B R 5
")

df %>%
  group_by(Maneuver, System) %>%
  shapiro_test(value)

错误:mutate() 输入 data 有问题。 x 必须按.data 中的变量分组。

  • 未找到列variable。 i 输入datamap(.data$data, .f, ...)

有人知道我该如何解决吗?是因为我缺少数据吗?

谢谢!!

【问题讨论】:

    标签: r


    【解决方案1】:

    将结果存储在列表中,然后您可以使用unnest_wider 获取不同列中的输出。

    library(dplyr)
    library(rstatix)
    
    df %>%
      group_by(Maneuver, System) %>%
      summarise(result = list(shapiro_test(value))) %>%
      tidyr::unnest_wider(result) %>%
      ungroup()
    
    #  Maneuver System variable statistic p.value
    #  <chr>    <chr>  <chr>        <dbl>   <dbl>
    #1 E        A      value        0.75    0    
    #2 E        B      value        1       1.00 
    #3 R        A      value        0.75    0    
    #4 R        B      value        0.964   0.637
    

    【讨论】:

      【解决方案2】:

      splitting 之后由群组提供base R 的选项

      library(broom)    
      out <- do.call(rbind, lapply(split(df, df[c("Maneuver", "System")]), 
           function(x) {
        x1 <- shapiro.test(x$value)
      cbind(x[1, c("Maneuver", "System")], 
             statistic = x1$statistic, p.value = x1$p.value) }))
      
      row.names(out) <- NULL
      out
      #    Maneuver System statistic   p.value
      #1        E      A 0.7500000 0.0000000
      #2        R      A 0.7500000 0.0000000
      #3        E      B 1.0000000 1.0000000
      #4        R      B 0.9642857 0.6368868
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-11-27
        • 1970-01-01
        • 2020-11-08
        • 2014-04-06
        • 1970-01-01
        • 1970-01-01
        • 2018-04-18
        • 2014-04-16
        相关资源
        最近更新 更多