Obtaining unexpectedly large p-value (chi square) i have no much experience coding nor with statistics so sorry and thank you in advance.
I'm trying to find out if two variables (living in urban or rural areas) and using medicine A or B (due to accessibility) are related. I have a data frame with many other variables and thousands of cases on which i'm doing the analysis. This is the grouped data
$data
           Outcome (medicine)

Predictor 1    2    Total

Urban     1412 1792  3204
Middle    885  1167  2052
Rural     485  662   1147
Total     2782 3621  6403 

I've tried using both chisq.test, and oddsratio.wald, obtaining with both a p.value of around 0.54, thus i can't reject the Null hypothesis and should assume that both may not be related at all, nevertheless if we look at the percentages we can see that there is a trend, in which the more rural the area, the less percentage use medicine 1.
          % use of Total
Urban     44.07% 
Middle    43.13%  
Rural     42.28%

So shouldn't i be obtaining a very low (<0.05) p value? am i doing something wrong?
I've used:
chiurba<-chisq.test(dfbi$TIPOANTICONCEP,dfbi$DEGURBA,simulate.p.value = TRUE)

and
ORurba<-oddsratio.wald(dfbi$DEGURBA,dfbi$TIPOANTICONCEP)

Thank you in advance
 A: A crude but effective way of estimating uncertainty in those kind of problems is  by taking the square root of the number of observations (which is approximately the standard deviation of a Binomial distribution).
So for example the percentage of using medicine 1 in the rural case would be estimated as
$$ \frac{485 \pm \sqrt{485}}{1147} \approx (42.3 \pm 1.9)\% $$
which is less than 1 standard deviation away from the urban case. So, despite the suggestive trend, it is not very significant.
A: Statistical significance is a measure for how probable the magnitude of a certain observed effect is when there would have been, in reality, no effect.
The motivation for this is that we use observations to measure some population, but our measurements have variations and do not exactly represent the true values of the population.
If certain samples are not accurate or very representative, due to statistical variations in the sampling or measurements, then we may still measure a certain effect even if there is not a true effect.
We call a measurement statistically significant if, assuming that there is no effect, the magnitude of an observed effect is not likely to occur due to the statistical variations.

So you measure some differences 44.07%, 43.13%, 42.28%.
But, for the given sample sizes there will likely be such variations and differences in a sample even if the true percentages in the population are equal.
A: If you are thinking about Location as a ordinal variable, you should probably treat it that way in the analysis.  One classic test of association that would be applicable here is the Cochran–Armitage test.  I believe this test doesn't actually treat the one variable as truly ordinal, but you have to assume the spacing between the categories.
However, since you have labeled Location as "Predictor" and Drug as "Outcome", you would want to use a model that explicitly treats one variable as the independent variable and one variable as the dependent variable.  In this case, logistic regression, using Location as on ordinal independent variable would work.
I tried both if these approaches with your data.  Each brings the p-value down to < 0.3. This is (sometimes !) the advantage of treating an ordinal variable as ordinal.
The upshot:  You do have a little bit of a trend over location, but whether or not you got a low p-value, and for whichever statistical approach you took, the question is really, Is a difference between 42% and 44% for Drug A important in this context?
I have R code for these analyses below.  I have more information on the Cochran–Armitage test at the following link, with the caveat that I wrote it. rcompanion.org/handbook/H_09.html
Input =(
   "Drug     A    B
Location  
Urban     1412 1792
Middle    885  1167
Rural     485  662
")

Tabla = as.table(read.ftable(textConnection(Input)))

Tabla

prop.table(Tabla,
           margin = 1)

library(coin)

spineplot(Tabla)

library(coin)

chisq_test(Tabla, scores = list("Location" = c(-1, 0, 1)))

##########################################

Data = read.table(header=TRUE, text="
Location  Drug Count
Urban     A    1412 
Middle    A     885  
Rural     A     485  
Urban     B    1792
Middle    B    1167
Rural     B     662
")

Data$Location = factor(Data$Location, 
                       levels = c("Urban", "Middle", "Rural"), ordered=TRUE)

Data$Drug = factor(Data$Drug)

library(tidyr)

Long = uncount(Data, Count)

xtabs(~ Location + Drug, data=Long)

model = glm(Drug ~ Location, data=Long, family=binomial())

summary(model)

