I am trying to run a beta regression using the betareg
package and I am using the following script:
require(betareg)
betareg(response ~ predictor
,na.action = na.omit
,weights = sqrt(total)
, data = ex.dat.new)
And R returns this error:
Error in betareg(response ~ predictor, na.action = na.omit, weights = sqrt(total), :
invalid dependent variable, all observations must be in (0, 1)
However, the dependent variable (named "response" here) IS constrained between 0 and 1.
Why is R returning this error and how can I correct it?
Data:
dput(ex.dat.new)
structure(list(predictor = structure(c(2L, 2L, 2L, 2L, 2L, 2L,
3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L,
5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L, 8L, 8L,
8L, 8L, 8L, 8L, 9L, 9L, 9L, 9L, 9L, 9L, 10L, 10L, 10L, 10L, 10L,
10L, 1L, 1L, 1L, 1L, 1L, 1L, 11L, 11L, 11L, 11L, 11L, 11L, 12L,
12L, 12L, 12L, 12L, 12L), .Label = c("Asoca", "bida", "coma",
"cyro", "melo", "oeno", "pano", "sena", "sida", "soam", "soda",
"verb"), class = "factor"), response = c(1, 1, 0.981270985, 1,
0.911258698, 1, 0.249252611, 0.671639842, 0.575247687, 0.943358751,
0.470602887, 0.875696109, 1, 1, 1, 1, 1, 1, 1, 0.131273134, 0.479774791,
0.497419936, 0.54108693, 0.838144234, 1, 1, 1, 1, 0.868294819,
1, 1, 1, 1, 1, 1, 1, 0.305218209, 1, 1, 1, 1, 0.095933078, 1,
1, 1, 1, 1, 1, 0.217037264, 0.410118055, 0.173707357, 0.200733967,
0.469833694, 0.208464348, 0.407013896, 0.846212651, 0.299872736,
0.965380984, 0.251676335, 0.806683955, 1, 1, 1, 1, 1, 1, 0.934555905,
0.564142452, 1, NA, 1, 0.029682211), total = c(109.98, 46.834,
293.662, 197.144, 59.927, 7.33, 70.579, 222.125, 201.767, 43.802,
417.541, 143.117, 70.658, 167.073, 666.542, 49.872, 258.847,
93.83, 56.036, 116.17, 378.5276, 12.209, 163.58, 182.329, 209.913,
411.1590278, 1003.223, 29.3499744, 95.896, 160.8383437, 124.437,
52.017, 187.045, 132.032, 67.188, 86.12, 171.189, 21.27, 29.69,
106.1, 77.14, 56.185, 68.97225736, 17.475, 539.401, 5.9, 49.256,
12.854, 342.015, 250.562, 2177.605021, 748.1001011, 1035.573167,
275.414, 660.717, 323.102, 1273.727, 285.97, 212.368, 140.366,
420.044, 54.295, 802.118, 150.612, 157.469, 85.275, 368.131,
35.998, 349.624, 0, 13.207, 191.731)), class = "data.frame", row.names = c(NA,
-72L))
NA
in the responses; but more important are the many exact values of $1.$ If we interpret the(0, 1)
of the error message to mean the open interval $(0,1)=\{x\mid0\lt x\lt1\},$ that would explain the problem. These data don't look suitable for beta regression. (All beta densities are either zero or not well defined at the values $0$ and $1.$) Correcting the error, then, requires choosing a suitable model. We can't help you with that unless you provide information about what your data mean and what you're trying to accomplish with this regression. $\endgroup$