Can the Chi-Square Value be Used to Quantitatively Discuss Goodness of Fit for any Data?

To quantitatively discuss the relationship between experimentally measured results and a fitted curve, is obtaining the Chi-Square value for my data relevant? By that I mean if I obtain the Chi-square value from the following figure (using the mean points) and compare it using the respective degrees of freedom (2, since i used the equation $$a/(bx+c)$$ to obtain the fit) on a Chi-square table, is the resulting probability value at all relevant for discussion? Also how would I more quantitatively explain this value.

In addition, if this strategy is not applicable to my case, could someone suggest another method of quantitatively discussing my fitted curve and data?

Here is the data table used to plot the figure:

• The variance is estimated at each x-value? Mar 18, 2020 at 2:25
• Or is it based on some previously established size of error? Mar 18, 2020 at 3:27
• The errorbars shown in the figure represent the standard deviation for each 'set' of points. Where a 'set' would mean all data points collected during transmission % of 20, 40, 60, 80 and 100. For example, the standard deviation on the 40% transmission data is 0.62. If I am interpreting you're question correctly, could I not just square this value to obtain variance at each transmission %? Mar 18, 2020 at 16:32
• Yes. Given a model with a,b and c all being free parameters is not identifiable, how did you resolve that non-identifiability? Also how is the fitting done? Note that ordinary nonlinear least squares assumes constant spread, which you don't have, so what did you do instead? [You might consider instead looking at Recharge speed (recharge rate) rather than recharge time as your response; it might make life easier] Mar 19, 2020 at 2:25
• Using python (numpy package) I used .optimize.curve_fit() which uses the non-linear least squares to fit coefficients. I am unfamiliar with the necessary requirement of constant spread, can you elaborate? In addition, looking at recharge rate I assume means taking this reciprocal relationship and turning it into a linear one. If so, I have done this and fitted the curve using the linear least squares approach. Would I be able to take this fitted curve and quantitatively explain it using the chi-square approach as I reference in my original post? Mar 19, 2020 at 16:32

The answer is "kind of". Many goodness of fit tests boil down to computing a test statistic which is chi-squared distributed. The most notable example is the deviance goodness of fit test for a poisson regression. In the case where the poisson regression is used to model contingency tables, then the two test statistics are the same. But, I digress. Let's discuss goodness of fit for your model.

Your data looks to be continuous, and the variance of the outcome seems to change with the conditional mean (variance of outcome gets smaller as the predictions get smaller). One possible way of assessing this model would be through a lognormal regression. However, since you posit the conditional mean is an inverse function (looks like 1/x) a gamma glm with the a canonical link function might be better. Let's simulate some data I made up.

I can fit a gamma regression to this data using

model = glm(y~x, family = Gamma())

Here is the predicted model in red as compared to the true conditional mean in black

Because we are using a glm, we can use the deviance goodness of fit test to determine how well our model fits. You are free to read up on the rationale behind the test, but I will show you how it can be computed.

d = deviance(model)
pchisq(d, df = model\$df.residual, lower.tail = F)


This returns a p value. We want this value to be larger than 0.05 because the null of the deviance goodness of fit test is that the proposed model does just as well as a model which perfectly predicts the data (I'm paraphrasing and you really should look at the details). Because we fail to reject the null of this test, we can conclude our model fits the data.

Now, I'm being a bit fast and loose, not only with the deviance goodness of fit test, but also with the choice of a gamma glm. You will have to determine which likelihood is most appropriate for you given your understanding of the data generating process.

Using the data you provide...

library(tidyverse)

y = c(14.62, 7.35, 11.19, 8.57, 12.19,
7.25, 5.81, 5.96, 5.75, 6.37,
4.75, 5.50, 5.91, 5.00, 4.34,
4.81, 5.13, 3.63, 4.28, 4.94,
3.47, 3.95, 3.84, 4.30, 3.44)

x = sort(rep(c(20,40,60,80,100),5))

d = tibble(x = x, y = y)

model = glm(y~x, data = d, family = Gamma())

d %>%
ggplot(aes(x,y))+
stat_summary(fun.data = function(x) mean_se(x,1.96))+
geom_smooth(method = 'glm', method.args = list(family = Gamma()), aes(color = 'Inverse Link'), se = F)



The deviance goodness of fit test returns a large p value (essentially 1) so we conclude this model fits well (again, being fast and loose).

• Fantastic explanation, I'll definitely have to read up on most terms you recited in this but this helps a lot. My only other question is that if I transform the x-axis by taking its reciprocal, the data becomes linear (as I said in my last comment). Are there any techniques that are more simplified in applying a goodness of fit test to this, now, linear model? Mar 20, 2020 at 1:13
• @NewToStats The data are linear now, but the show heterogeneity of variance. You could just do linear regression and compute R squared, but I would not do any hypothesis tests. Let me do this example with the data you've provided. Can you tell me a little more about the design of the experiment and what you are measuring (i.e. the outcome)? Mar 20, 2020 at 1:30
• The experiment starts with the splitting of monochromatic light into the visible light spectra (i.e violet, blue, green, yellow etc.). An apparatus with a photodiode is then placed in a position such that the desired choice of spectral light shines into the 'mask'. Within the mask is a cathode and anode, photoelectrons are excited due to the material's low work function and the measurement of the stopping potential is possible. A transmission filter is then placed over the spectral light's entrance to the mask, so that 20%, 40%, 60% etc of the spectral light is able to pass through. Mar 20, 2020 at 17:02
• The 'recharge time' measurement was made as follows: The photodiode apparatus is able to 'discharge', meaning that the spectral light must then excite an amount of photoelectrons to once again reach the recorded stopping potential. The time it takes for the electrons to reach this stopping potential at each 20% increment of transmission was recorded for green spectral light. Mar 20, 2020 at 17:05
• Now that the explanation is out of the way, the 'outcome' of this section of the experiment is to support the quantum model of light. 'Do the results support the quantum model prediction that increased intensity would increase the number of photoelectrons emitted (photoelectric current) but not the energy of the photoelectrons?' The answer is obviously yes because at higher transmission percentages, the faster the the apparatus is able to come back from a discharge while still staying at the approximately similar stopping potential. Mar 20, 2020 at 17:08