How to control for n when using proportion for modelling? I am trying to fit a logistic model on binary variable y, using p as an independent variable.
p was calculated by this formula : x/n where x is number of successes and n is number of trials. However not all of the observations have the same n in my data.
How can I measure the effect of p on y while controlling for n?. I tried adding a control variable sqrt(p*(1-p)/n) (margin of error without the critical z value) to the model but this does not work if p==0 or p==1 and it does not have any significant effect on the dependent variable. Is there a better way to do this?
Edit: Let me give an example.If n = 3, p can only take 4 values (0,0.33,0.66,1) and it does not represent the true proportion of the population because of the low sample size. So how can i build a model such that it dampens the effect of p when n is small but increases the effect when n is higher?

Using the binomial distribution for your likelihood function is the obvious answer. The most popular way of doing that is logistic regression, which assumes $Y_i \sim \text{Binomial}(n, \pi_i)$ and uses a logit-link function to lin any predictors you use in your model to the probability $\pi_i$ via $\log \pi_i - \log(1-\pi_i) = \beta_0 + \beta_1 * x_{i1} + \ldots$.
I.e. this looks a lot like a linear regression, but instead of modelling the proportion directly, you are modeling the logit of the probability. Additionally, instead of normally distributed error terms, the randomness is accounted for via the binomial distribution.
Most statistical software directly allows you to specify that your data is y out of n. For example in R, you can use glm( cbind(y, n-y) ~ x1 + x2, data = myexample, family = "binomial") to fit such a model (the notation with cbind(y, n-y) let's you specify the number of successes and failures associated with a record).
