tpetzoldt / growthrates

R Package growthrates
GNU General Public License v2.0
26 stars 7 forks source link

subscript out of bounds #4

Closed brmagalis closed 4 years ago

brmagalis commented 4 years ago

I am getting the following error:

Error in sm$coefficients[2, 1] : subscript out of bounds

for

fit_easylinear(g$data$time, g$data$nemed).

I have attached the 'g' file as an RDS. g.rds.zip

tpetzoldt commented 4 years ago

This seems to be off topic for github, that is a developer site, not for such questions.

You may consider to send a minimal reproducible example to stackoverflow, i.e. a data set in text or csv format (no binary!) and a complete script.

Regards, Thomas

On 25.06.2020 at 21:54 Brittany Rife Magalis wrote:

I am getting the following error:

Error in sm$coefficients[2, 1] : subscript out of bounds

for

fit_easylinear(g$data$time, g$data$nemed).

I have attached the 'g' file as an RDS. g.rds.zip https://github.com/tpetzoldt/growthrates/files/4833520/g.rds.zip

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/tpetzoldt/growthrates/issues/4, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACFLRXQKJHTBSAANOXR552DRYOTQVANCNFSM4OIWA63Q.

tpetzoldt commented 4 years ago

Even if the style of the error report was somewhat off topic, it points to an interesting issue of R's lm function that fit_easylinear uses. Try the following:

x <- 1000 + seq(0, 1e-5, length.out=5)
y <- seq(0, 1e-5, length.out=5)
plot(x, y)
m <- lm(y ~ x)
summary(m)

where lm is not able to estimate the slope due to numerical reasons, see the NA values in the last row of the coefficient table:

Call:
lm(formula = y ~ x)

Residuals:
         1          2          3          4          5 
-5.000e-06 -2.500e-06 -2.118e-22  2.500e-06  5.000e-06 

Coefficients: (1 not defined because of singularities)
             Estimate Std. Error t value Pr(>|t|)  
(Intercept) 5.000e-06  1.768e-06   2.828   0.0474 *
x                  NA         NA      NA       NA  
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 3.953e-06 on 4 degrees of freedom

Workaround: shift your data to the left by subtracting a certain value from your x data, e.g. 1000 in the example above.

I'll think about it and consider to add a suitable error message. Next time please add your test data in text format, not binary. But anyway, many thanks for the report.

brmagalis commented 4 years ago

Thanks, Thomas. I know it’s not the norm, but I haven’t had much luck on SO lately ( is everyone on vacation?), so I took some desperate measures. I would never have guessed to shift the data, so thank you!! I I’ll steer clear of your git from now on :)

On Jun 25, 2020, at 5:01 PM, Thomas Petzoldt notifications@github.com wrote:

Even if the style of the error report was somewhat off topic, it points to an interesting issue of R's lm function that fit_easylinear uses. Try the following:

x <- 1000 + seq(0, 1e-5, length.out=5) y <- seq(0, 1e-5, length.out=5)

plot(x, y)

m <- lm(y ~ x) summary(m) where lm is not able to estimate the slope due to numerical reasons:

Call: lm(formula = y ~ x)

Residuals: 1 2 3 4 5 -5.000e-06 -2.500e-06 -2.118e-22 2.500e-06 5.000e-06

Coefficients: (1 not defined because of singularities) Estimate Std. Error t value Pr(>|t|)
(Intercept) 5.000e-06 1.768e-06 2.828 0.0474 * x NA NA NA NA

Signif. codes: 0 ‘’ 0.001 ‘’ 0.01 ‘’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 3.953e-06 on 4 degrees of freedom Workaround:

shift your data to the left by subtracting a certain value from your x data.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.