Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3450710
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:04:38+00:00 2026-05-18T09:04:38+00:00

I used model fitting to fit the negative binomial distribution to my discrete data.

  • 0

I used model fitting to fit the negative binomial distribution to my discrete data. As a final step it looks like I need to perform a Kolmogrov-Smirnov test to determine if the model fits the data well. All the references I could find talk about using the test for normally distributed continuous data. Can someone tell me if this can be done in R for data that is not normally distributed and discrete? (Even a chi-square test should do I’m guessing but please correct me if I’m wrong.)

UPDATE:

So I found that the vcd package contains a function goodfit that can be used for this purpose in the following way:

library(vcd)

# Define the data
data <- c(67, 81, 93, 65, 18, 44, 31, 103, 64, 19, 27, 57, 63, 25, 22, 150,
          31, 58, 93, 6, 86, 43, 17, 9, 78, 23, 75, 28, 37, 23, 108, 14, 137,
          69, 58, 81, 62, 25, 54, 57, 65, 72, 17, 22, 170, 95, 38, 33, 34, 68,
          38, 117, 28, 17, 19, 25, 24, 15, 103, 31, 33, 77, 38, 8, 48, 32, 48,
          26, 63, 16, 70, 87, 31, 36, 31, 38, 91, 117, 16, 40, 7, 26, 15, 89,
          67, 7, 39, 33, 58)

gf <- goodfit(data, type = "nbinomial", method = "MinChisq") 
plot(gf)

But after the gf <- ... step, R complains saying:

Warning messages:
1: In pnbinom(q, size, prob, lower.tail, log.p) : NaNs produced
2: In pnbinom(q, size, prob, lower.tail, log.p) : NaNs produced
3: In pnbinom(q, size, prob, lower.tail, log.p) : NaNs produced

and when I say plot it complains:

Error in xy.coords(x, y, xlabel, ylabel, log) : 
  'x' is a list, but does not have components 'x' and 'y'

I am not sure what is happening because if I set data to be the following:

data <- <- rnbinom(200, size = 1.5, prob = 0.8)

everything works fine. Any suggestions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T09:04:38+00:00Added an answer on May 18, 2026 at 9:04 am

    A KS-Test is for continuous variables only, plus you have to fully specify the distribution you are testing against. If you still wanted to do it, it would look like this:

    ks.test(data, pnbinom, size=100, prob=0.8)
    

    It compares the empirical cumulative distribution function of data against the specified one (whether that makes sense probably depends on your data). You would have to choose parameters for size and prob based on theoretical considerations, the test is not valid if you estimate those parameters based on the data.

    Your problem with goodfit() might have to do with your data, are you sure these are counts? barplot(table(data)) does not look like it’s approximately following a negative binomial distribution, compare, e.g., with barplot(table(rnbinom(200, size = 1.5, prob = 0.8)))

    Finally, I’m not sure if the approach of doing a null-hypothesis test after fitting is appropriate. You may want to look into quantitative fit measures beyond / based on $\chi^2$ of which there are many (RMSEA, SRMR, …).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What types of applications have you used model checking for? What model checking tool
My model layer is being used by a handful of different projects and I'd
I'm used to the Java model where you can have one public class per
In a forms model, I used to get the current logged-in user by: Page.CurrentUser
Never used a cache like this before. The problem is that I want to
I am creating a small modal form that is used in Winforms application. It
We used the undocumented xp_fileexist stored procedure for years in SQL Server 2000 and
I used the LINQ to SQL designer in Visual Studio to create an object
I used to work in a place where a common practice was to use
I used jQuery to set hover callbacks for elements on my page. I'm now

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.