ANOVA: Degrees of freedom almost all equal 1

后端 未结 1 706
我寻月下人不归
我寻月下人不归 2021-01-12 15:17

I have a data set that begins like this:

> d.weight
    R   N   P  C D.weight
1   1   0   0 GO     45.3
2   2   0   0 GO     34.0
3   3   0   0 GO     19.         


        
1条回答
  •  隐瞒了意图╮
    2021-01-12 16:06

    R determines whether it should treat variables as categorical (ANOVA-type analysis) or continuous (regression-type analysis) by checking whether they are numeric or factor variables. Most simply, you can convert your predictor (independent) variables to factors via

    facs <- c("R","N","P")
    d.weight[facs] <- lapply(d.weight[facs],factor) 
    

    If you want to create auxiliary variables instead of overwriting you could do something like

    for (varname in facs) {
       d.weight[[paste0("f",varname)]] <- factor(d.weight[[varname]])
    }
    

    There might be a more compact way to do it but that should serve ...

    0 讨论(0)
提交回复
热议问题