在lm错误。适合(x, y,偏移=偏移,单数。好吧=奇异。好的,……)0个非na的案例(moult包)

时间:2022-02-19 17:55:27

I'm new to R and don't understand much about how it works. I'm trying to run this code however the "Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) : 0 (non-NA) cases" constantly appears and my data actually has no NA. So what should I do?

我对R很陌生,也不太了解它的工作原理。我试图在lm中运行这个代码。适合(x, y,偏移=偏移,单数。好吧=奇异。好的,…):0(非NA)情况“经常出现,我的数据实际上没有NA。那我该怎么做呢?

> library("moult")
> 
> mym = read.csv("Test.csv", sep=";", head=T)
> head(mym)
    Age Sex  MoultPresence      Score Prim Habitat Jul.Day
1 Adult   1             1 5554210000   22   Beach     123
2 Adult   2             1 5555321000   26 Estuary     124
3 Adult   1             1 5555553200   35 Estuary     124
4 Adult   1             1 4440000000   12   Beach     126
5 Adult   2             1 5555532100   31 Mudflat     127
6 Adult   1             1 5555321000   26 Mudflat     127

> if (is.numeric(mym$Prim)) {scores <- format(mym$Prim, scientific = FALSE, trim = TRUE)} else {scores <- mym$Prim}
> mscores <- substr(scores, 1, 9)
> mym$Date <- date2days(mym$Date, dateformat = "dd-mm-yyyy", startmonth = 9)
> m88.2 <- moult(Prim ~ Jul.Day, data = mym)
Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) : 
  0 (non-NA) cases

> summary(m88.2)
Error in summary(m88.2) : object 'm88.2' not found

> m88c <- moult(Prim ~ Jul.Day, data = mym, type = 3)
Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) : 
  0 (non-NA) cases

> summary(m88c)
Error in summary(m88c) : object 'm88c' not found

> durationmean2ab <- function(duration, mean) {
+   ab <- c(-mean/duration, 1/duration) 
+   names(ab) <- c("intercept", "slope") 
+   return(ab) 
+ }
> uz1 <- durationmean2ab(coef(m88c, "duration"), coef(m88c, "mean"))
Error in coef(m88c, "mean") : object 'm88c' not found

> 
> ssex <- ifelse(mym$Sex == 1 | mym$Sex == 3, "male", ifelse(mym$Sex == 2 | mym$Sex == 4, "female", NA))
> mym$ssex <- as.factor(ssex)
> mmf <- moult(Prim ~ Jul.Day | ssex | ssex, data = mym, type = 3)
Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) : 
  0 (non-NA) cases

Could any of you have any idea about how to fix it?

你们中有人知道怎么修理吗?

1 个解决方案

#1


1  

It helps to Read the Fine Manual ... Taking a quick look at the vignette for the moult package (emphasis added):

它有助于阅读精美的手册……快速浏览一下模具包装的简介(重点补充):

formula can have five parts, of which the first two (moult.index and days) must always be provided:

公式可以分为五个部分,其中前两个部分(moult)。索引和日期必须始终提供:

moult.index ~ days | x1 + x2 | y1 + y2 | z1

蜕皮。指数-日| x1 + x2 | y + y2 | z1。

On the left-hand-side of the ∼ the vector of moult indices (between 0 and 1, one for each individual) is given, the first part after the ∼ requires a vector of corresponding days on which these individuals were observed (number of days since, e.g., 1 July).

在图的左侧,给出了模型的向量(在0到1之间,每个个体都有一个),第一部分在之后的第一部分需要一个对应的时间向量来观察这些个体(从7月1日开始的天数)。

Earlier in the same document:

在同一份文件的早些时候:

This moult index can be the original sum of moult scores, or some transformation of these to make the index linear... It is convenient to scale this index to range from 0 to 1.

这个模型的索引可以是模型分数的原始和,或者是一些变换使指数线性…将该索引扩展到从0到1的范围很方便。

So I'd suggest starting with:

所以我建议从以下几点开始:

mym <- transform(mym, Prim_scaled = (Prim-min(Prim))/(max(Prim)-min(Prim)))
moult(Prim_scaled ~ Jul.Day, data = mym)

This appears to work OK (with moult version 1.4) with the subset of the data you've shown us:

这似乎可以(与moult版本1.4)一起使用您向我们展示的数据的子集:

mym <- read.table(header=TRUE,
                  text="
Age Sex  MoultPresence      Score Prim Habitat Jul.Day
1 Adult   1             1 5554210000   22   Beach     123
2 Adult   2             1 5555321000   26 Estuary     124
3 Adult   1             1 5555553200   35 Estuary     124
4 Adult   1             1 4440000000   12   Beach     126
5 Adult   2             1 5555532100   31 Mudflat     127
6 Adult   1             1 5555321000   26 Mudflat     127")

mym <- transform(mym, Prim_scaled = (Prim-min(Prim))/(max(Prim)-min(Prim)))
moult(Prim_scaled ~ Jul.Day, data = mym)

Unless you can provide a reproducible example, we probably can't get any farther.

除非你能提供一个可复制的例子,否则我们可能无法再进一步了。

#1


1  

It helps to Read the Fine Manual ... Taking a quick look at the vignette for the moult package (emphasis added):

它有助于阅读精美的手册……快速浏览一下模具包装的简介(重点补充):

formula can have five parts, of which the first two (moult.index and days) must always be provided:

公式可以分为五个部分,其中前两个部分(moult)。索引和日期必须始终提供:

moult.index ~ days | x1 + x2 | y1 + y2 | z1

蜕皮。指数-日| x1 + x2 | y + y2 | z1。

On the left-hand-side of the ∼ the vector of moult indices (between 0 and 1, one for each individual) is given, the first part after the ∼ requires a vector of corresponding days on which these individuals were observed (number of days since, e.g., 1 July).

在图的左侧,给出了模型的向量(在0到1之间,每个个体都有一个),第一部分在之后的第一部分需要一个对应的时间向量来观察这些个体(从7月1日开始的天数)。

Earlier in the same document:

在同一份文件的早些时候:

This moult index can be the original sum of moult scores, or some transformation of these to make the index linear... It is convenient to scale this index to range from 0 to 1.

这个模型的索引可以是模型分数的原始和,或者是一些变换使指数线性…将该索引扩展到从0到1的范围很方便。

So I'd suggest starting with:

所以我建议从以下几点开始:

mym <- transform(mym, Prim_scaled = (Prim-min(Prim))/(max(Prim)-min(Prim)))
moult(Prim_scaled ~ Jul.Day, data = mym)

This appears to work OK (with moult version 1.4) with the subset of the data you've shown us:

这似乎可以(与moult版本1.4)一起使用您向我们展示的数据的子集:

mym <- read.table(header=TRUE,
                  text="
Age Sex  MoultPresence      Score Prim Habitat Jul.Day
1 Adult   1             1 5554210000   22   Beach     123
2 Adult   2             1 5555321000   26 Estuary     124
3 Adult   1             1 5555553200   35 Estuary     124
4 Adult   1             1 4440000000   12   Beach     126
5 Adult   2             1 5555532100   31 Mudflat     127
6 Adult   1             1 5555321000   26 Mudflat     127")

mym <- transform(mym, Prim_scaled = (Prim-min(Prim))/(max(Prim)-min(Prim)))
moult(Prim_scaled ~ Jul.Day, data = mym)

Unless you can provide a reproducible example, we probably can't get any farther.

除非你能提供一个可复制的例子,否则我们可能无法再进一步了。