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:
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)
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.