Error: numeric send argument has no length one

Asked

Viewed 250 times

2

I am trying to check the probability of the draw of number 5 in a bingo game.

I would like some tips for those who are starting. Maybe the function lm is not ideal for this problem.

The initial program is simple:

setwd("d:\\Bingo.R")

cartela = 1:25

numerosSorteados <- c(1,2,3,4)

modelo <- lm(formula = cartela$v1 ~ numerosSorteados, data=cartela)

I’m getting the error below:

Error in Eval(predvars, data, env) : argument 'send' numeric has no length one

Could someone explain to me what this mistake would be?

Note: my environment is set to English but the messages are mixed between English and Portuguese.

1 answer

4

Rather, two definitions:

  • A vector is a collection of n elements of the same type.

  • The function lm means linear model (linear model). Simplifying much, in its simplest version, what it does is to adjust the best possible line to two vectors.

Take, for example, the data set cars. It has observations on the speed and distance that cars took to stop completely from having the brakes on. There are 50 lines and two columns, totaling 100 observations. Each car contributes two of them: one for speed and one for distance. Note that it is possible to plot these observations on a graph:

inserir a descrição da imagem aqui

The function lm will serve to adjust a straight to this data:

ajuste <- lm(dist ~ speed, data = cars)
summary(ajuste)

Call:
lm(formula = dist ~ speed, data = cars)

Residuals:
    Min      1Q  Median      3Q     Max 
-29.069  -9.525  -2.272   9.215  43.201 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept) -17.5791     6.7584  -2.601   0.0123 *  
speed         3.9324     0.4155   9.464 1.49e-12 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 15.38 on 48 degrees of freedom
Multiple R-squared:  0.6511,    Adjusted R-squared:  0.6438 
F-statistic: 89.57 on 1 and 48 DF,  p-value: 1.49e-12


abline(ajuste)

inserir a descrição da imagem aqui

Note that to use the function lm, it is obligatory that dist and speed are the same size:

length(cars$dist)
[1] 50
length(cars$speed)
[1] 50

In your case, that doesn’t happen:

length(cartela)
[1] 25
length(numerosSorteados)
[1] 4

Moreover, cartela$v1 there is no:

length(cartela$v1)
Error in cartela$v1 : $ operator is invalid for atomic vectors

Therefore, the best way to answer the question "check the probability of the draw of number 5 in a bingo game" is by creating a frequency table and calculating the odds of each number coming out:

prop.table(table(numerosSorteados))
numerosSorteados
   1    2    3    4 
0.25 0.25 0.25 0.25 

In this case, the probabilities of 1, 2, 3 and 4 are the same, equal to 0.25 (or 25%). All other numbers in the chart have a probability of zero being chosen, as they were never drawn.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.