I'm new to R (and statistics in general) so apologies in advance for what's probably a very remedial question, but I'd appreciate any help!
I'm trying to assess if there's a statistical advantage to starting a motor race in a given lane over another.
The sample sizes I have are small and not necessarily normally distributed so I'm opting to use a chi sq test to check for a significant difference between the expected vs observed wins.
#create lanes var
lane_num <- c(1:10)
#num wins per lane
num_wins <- c(8, 7, 10, 7, 6, 3, 6, 4, 1, 0)
#create df
df <- as.data.frame(cbind(lane_num, num_wins))
#convert lanes_num factor
df$lane_num <- as.factor(df$lane_num)
#check str
str(df)
#run chisq
chi_res <- chisq.test(df$num_wins)
#check results
chi_res
#check for sig diff between lanes
chisq.post.hoc(df) #this is where i'm having issues
The result of the chisq.test gives the following results suggesting a significant difference between expected v observed;
Chi-squared test for given probabilities
data: df$num_wins
X-squared = 17.231, df = 9, p-value = 0.04522
Where I'm struggling is when it comes to running a post-hoc test between lanes to see exactly which ones are significantly more advantageous to start from.
Simply running:
chisq.post.hoc(df)
returns the following error;
Error in test(tbl[prs[, i], ], ...) :
all entries of 'x' must be nonnegative and finite
As I say, I'm new to R and stats so the documentation provided regarding chisq.post.hoc doesn't make a lot of sense to me - plus it seems the package is no longer supported so i had to download an archived version. I've tried various things but all produce errors. For example;
chisq.post.hoc(df$num_wins, control = "bonferroni")
> Error in 1:nrow(tbl) : argument of length 0
I'd really appreciate a steer on this or any advise regarding an alternative post-hoc test I could use along with how the data needs to be structured before running etc.
Thanks in advance!
This is because you shouldn't use a data.frame but a table. I can't install fifer as it is no longer supported so here is a solution with RVAideMemoire:
race <- matrix(c(8, 7, 10, 7, 6, 3, 6, 4, 1, 0),ncol=10)
colnames(race) <- c(1:10)
race<-as.table(race)
race
#run chisq
chi_res <- chisq.test(race)
#check results
chi_res
library(RVAideMemoire)
chisq.multcomp(race, p.method = "none")
output:
> chi_res
Chi-squared test for given probabilities
data: race
X-squared = 17.231, df = 9, p-value = 0.04522
> chisq.multcomp(race, p.method = "none")
Pairwise comparisons using chi-squared tests
data: race
0 1 3 4 6 6 7 7 8
1 0.3173 - - - - - - - -
3 0.0833 0.3173 - - - - - - -
4 0.0455 0.1797 0.7055 - - - - - -
6 0.0143 0.0588 0.3173 0.5271 - - - - -
6 0.0143 0.0588 0.3173 0.5271 1.0000 - - - -
7 0.0082 0.0339 0.2059 0.3657 0.7815 0.7815 - - -
7 0.0082 0.0339 0.2059 0.3657 0.7815 0.7815 1.0000 - -
8 0.0047 0.0196 0.1317 0.2482 0.5930 0.5930 0.7963 0.7963 -
10 0.0016 0.0067 0.0522 0.1088 0.3173 0.3173 0.4669 0.4669 0.6374
P value adjustment method: none
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With