# Perform ANOVA on imbalanced Data in Python

Is there a way I can perform ANOVA [or any statistical test] for the following research problem.

I have a variable Plant Survives (1/0) and another variable Amount of Hydrogen( Continous). I want to find if Plant Survival and Amount_Of_Hydrogen are dependent (or is there correlation between the plant survival and amount of hydrogen it is supplied)

How can I solve this for

• Balanced Data
• ImBalanced Data

My intuition is that I want to use ANOVA here. But, ANOVA needs Balanced class. Is there any other way to tackle it in PYTHON?

## 1 Answer

A logistic regression should suffice in this case. I happen to have some similar data I can use to demonstrate.

The data contain the level of herbicide applied to a group of plants, the total number of plants in the replicate, and the number of plants which died. Here is a representation of the proportion of plants which died for each concentration of herbicide. Each concentration has 3 replicates. The highest and lowest concentrations see all and no plants die respectively, which means the 3 dots are right on top of one another.

To analyze the relationship, we can use logistic regression (see the statsmodels package in python).

The imbalance/balance between groups is not an issue here. The goal here is estimation rather than classification, so the fact that groups may be imbalanced is actually a good thing. Once you fit your model, you will be able to output summaries of the model. Here is the summary for the model fit to my data

We can see here that that the effect of increasing the herbicide by one unit results in a 2.65 unit increase in the log odds of the plant dying.

I'm not prepared to walk through a detailed example of how to use logistic regression for estimation in this manner. Many examples exist on this site, several of which I have authored. This should set you down the right path. Look up the documentation for Logistic Regression in statsmodels (see here) to start.

• Using Logistic Reg. gives me coefficents, Like in the image 2.6. Then again I will have to take a call on threshold. Coefficent greater than what threshold is really significant. How can I come to conclusion of WHAT VALUE OF COEFFICENT ABOVE THRESHOLD means the Dependent and Independent variable is Correlated? May 24 '20 at 22:43
• How about Welchs Anova test ? It will tell me if the 2 variables are dependent or No. May 24 '20 at 22:47
• @chaitanya p values are provided by the summary method. I don't think an anova method would be appropriate since your predictor is continuous. May 24 '20 at 23:22
• Is Anova applied ONLY when dependent variable is Continous? In this case, can I not use Anova assuming Survived/Dead as Independent variables and Hydrogen amount as Dependent Variable? May 25 '20 at 0:01
• Anova is usually applied when the predictor is categorical. In your case, it sounds like the variable under our control is the concentration of hydrogen, not the alive/dead state. May 25 '20 at 0:02