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

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)

