Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cbc_power - "NA" generated for 'estimated coefficient' and 'standard errors' in Output #6

Closed
STEVEAP28 opened this issue Mar 5, 2023 · 13 comments

Comments

@STEVEAP28
Copy link

John --

When running cbc_tools with the Example from (https://rdrr.io/github/jhelvy/cbcTools/man/cbc_power.html)
I get the following Output with "NA"s for Estimated Coefficients and Standard Errors:

A simple conjoint experiment about apples

library(cbcTools)

Generate all possible profiles

profiles <- cbc_profiles(

  • price = c(1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5),
  • type = c("Fuji", "Gala", "Honeycrisp"),
  • freshness = c('Poor', 'Average', 'Excellent')
  • )

Make a randomized survey design

design <- cbc_design(

  • profiles = profiles,
  • n_resp = 300, # Number of respondents
  • n_alts = 3, # Number of alternatives per question
  • n_q = 6 # Number of questions per respondent
  • )

Simulate random choices

data <- cbc_choices(

  • design = design,
  • obsID = "obsID"
  • )

Conduct a power analysis

power <- cbc_power(

  • data = data,
  • pars = c("price", "type", "freshness"),
  • outcome = "choice",
  • obsID = "obsID",
  • nbreaks = 10,
  • n_q = 6
  • )
    Estimating models using 3 cores...
    done!

head(power)
sampleSize coef est se
1 30 price NA NA
2 30 typeGala NA NA
3 30 typeHoneycrisp NA NA
4 30 freshnessAverage NA NA
5 30 freshnessExcellent NA NA
6 60 price NA NA


I re-ran this several times -- but still get this "NA" Result. Am I missing something?

@jhelvy
Copy link
Owner

jhelvy commented Mar 5, 2023

You sometimes can get NA values with small sample sizes. That's my first guess of what's happening since you used head() to only view the first few rows of the result.

In the example that you referenced here, I cannot replicate the NA result. Here's what I get with that example:

set.seed(1234)
library(cbcTools)

# A simple conjoint experiment about apples

# Generate all possible profiles
profiles <- cbc_profiles(
  price     = c(1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5),
  type      = c("Fuji", "Gala", "Honeycrisp"),
  freshness = c('Poor', 'Average', 'Excellent')
)

# Make a randomized survey design
design <- cbc_design(
  profiles = profiles,
  n_resp   = 300, # Number of respondents
  n_alts   = 3, # Number of alternatives per question
  n_q      = 6 # Number of questions per respondent
)

# Simulate random choices
data <- cbc_choices(
  design = design,
  obsID  = "obsID"
)

# Conduct a power analysis
power <- cbc_power(
  data    = data,
  pars    = c("price", "type", "freshness"),
  outcome = "choice",
  obsID   = "obsID",
  nbreaks = 10,
  n_q     = 6
)

Now preview the results:

head(power)
#>   sampleSize               coef         est         se
#> 1         30              price -0.07194700 0.07609126
#> 2         30           typeGala  0.34172607 0.22791822
#> 3         30     typeHoneycrisp  0.50663546 0.22807907
#> 4         30   freshnessAverage  0.01794571 0.22327851
#> 5         30 freshnessExcellent  0.13248210 0.22751630
#> 6         60              price  0.02152378 0.05237815
tail(power)
#>    sampleSize               coef         est         se
#> 45        270 freshnessExcellent -0.17115823 0.07369265
#> 46        300              price  0.03658552 0.02240770
#> 47        300           typeGala  0.05830221 0.07098261
#> 48        300     typeHoneycrisp  0.04437270 0.07072744
#> 49        300   freshnessAverage -0.20545772 0.06966451
#> 50        300 freshnessExcellent -0.17473701 0.07007619

@STEVEAP28
Copy link
Author

John --

I copied and ran your code based on your initial reply. Unfortunately, I am still getting "NA" in the Estimates and Standard Errors (See below):

set.seed(1234)
library(cbcTools)
Version: 0.2.0
Author: John Paul Helveston (George Washington University)

Consider submitting praise at
#3.

Please cite the package in your publications, see:
citation("cbcTools")

A simple conjoint experiment about apples

Generate all possible profiles

profiles <- cbc_profiles(

  • price = c(1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5),
  • type = c("Fuji", "Gala", "Honeycrisp"),
  • freshness = c('Poor', 'Average', 'Excellent')
  • )

Make a randomized survey design

design <- cbc_design(

  • profiles = profiles,
  • n_resp = 300, # Number of respondents
  • n_alts = 3, # Number of alternatives per question
  • n_q = 6 # Number of questions per respondent
  • )

Simulate random choices

data <- cbc_choices(

  • design = design,
  • obsID = "obsID"
  • )

Conduct a power analysis

power <- cbc_power(

  • data = data,
  • pars = c("price", "type", "freshness"),
  • outcome = "choice",
  • obsID = "obsID",
  • nbreaks = 10,
  • n_q = 6
  • )
    Estimating models using 3 cores...
    done!

head(power)
sampleSize coef est se
1 30 price NA NA
2 30 typeGala NA NA
3 30 typeHoneycrisp NA NA
4 30 freshnessAverage NA NA
5 30 freshnessExcellent NA NA
6 60 price NA NA
power
sampleSize coef est se
1 30 price NA NA
2 30 typeGala NA NA
3 30 typeHoneycrisp NA NA
4 30 freshnessAverage NA NA
5 30 freshnessExcellent NA NA
6 60 price NA NA
7 60 typeGala NA NA
8 60 typeHoneycrisp NA NA
9 60 freshnessAverage NA NA
10 60 freshnessExcellent NA NA
11 90 price NA NA
12 90 typeGala NA NA
13 90 typeHoneycrisp NA NA
14 90 freshnessAverage NA NA
15 90 freshnessExcellent NA NA
16 120 price NA NA
17 120 typeGala NA NA
18 120 typeHoneycrisp NA NA
19 120 freshnessAverage NA NA
20 120 freshnessExcellent NA NA
21 150 price NA NA
22 150 typeGala NA NA
23 150 typeHoneycrisp NA NA
24 150 freshnessAverage NA NA
25 150 freshnessExcellent NA NA
26 180 price NA NA
27 180 typeGala NA NA
28 180 typeHoneycrisp NA NA
29 180 freshnessAverage NA NA
30 180 freshnessExcellent NA NA
31 210 price NA NA
32 210 typeGala NA NA
33 210 typeHoneycrisp NA NA
34 210 freshnessAverage NA NA
35 210 freshnessExcellent NA NA
36 240 price NA NA
37 240 typeGala NA NA
38 240 typeHoneycrisp NA NA
39 240 freshnessAverage NA NA
40 240 freshnessExcellent NA NA
41 270 price NA NA
42 270 typeGala NA NA
43 270 typeHoneycrisp NA NA
44 270 freshnessAverage NA NA
45 270 freshnessExcellent NA NA
46 300 price NA NA
47 300 typeGala NA NA
48 300 typeHoneycrisp NA NA
49 300 freshnessAverage NA NA
50 300 freshnessExcellent NA NA


Any other ideas to work around or through this? This is a useful function that would like to utilize

Look forward to your help.

Regards --
Steve

@jhelvy
Copy link
Owner

jhelvy commented Mar 6, 2023

Steve, I've replicated the code in a Google colab notebook here

You can see that with a fresh installation of cbcTools (v0.2.0), the example runs without producing NA values.

Can you copy-paste that exact code from the colab notebook and post the results? There must be an issue somewhere, perhaps just a simple typo? Can you confirm that you have installed v0.2.0 from CRAN?

@STEVEAP28
Copy link
Author

Hi John ---

Yes I did a "fresh installation" of cbcTools (v0.2.0). I have uninstalled and installed about 3 times. Below is the 'output' from just the 'installed' process.

Maybe you can see something there that is causing this 'NA' issue - as I am still getting that Result (see Results after the 'install' step below, as well).

install.packages('cbcTools')
Installing package into ‘C:/Users/Steve/Documents/R/win-library/4.0’
(as ‘lib’ is unspecified)
installing the source package ‘cbcTools’

trying URL 'https://cran.rstudio.com/src/contrib/cbcTools_0.2.0.tar.gz'
Content type 'application/x-gzip' length 1531222 bytes (1.5 MB)
downloaded 1.5 MB

  • installing source package 'cbcTools' ...
    ** package 'cbcTools' successfully unpacked and MD5 sums checked
    ** using staged installation
    ** R
    ** inst
    ** byte-compile and prepare package for lazy loading
    ** help
    *** installing help indices
    converting help for package 'cbcTools'
    finding HTML links ... done
    cbc_balance html
    cbc_choices html
    cbc_design html
    cbc_overlap html
    cbc_power html
    cbc_profiles html
    miscmethods.cbc_errors html
    miscmethods.cbc_models html
    randLN html
    randN html
    *** copying figures
    ** building package indices
    ** testing if installed package can be loaded from temporary location
    *** arch - i386
    *** arch - x64
    ** testing if installed package can be loaded from final location
    *** arch - i386
    *** arch - x64
    ** testing if installed package keeps a record of temporary installation path
  • DONE (cbcTools)

The downloaded source packages are in
‘C:\Users\Steve\AppData\Local\Temp\RtmpsdYCLM\downloaded_packages’

set.seed(1234)
library(cbcTools)
Version: 0.2.0
Author: John Paul Helveston (George Washington University)

Consider submitting praise at
#3.

Please cite the package in your publications, see:
citation("cbcTools")


Below are the colab notebook code and Results:

A simple conjoint experiment about apples

Generate all possible profiles

profiles <- cbc_profiles(

  • price = c(1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5),
  • type = c("Fuji", "Gala", "Honeycrisp"),
  • freshness = c('Poor', 'Average', 'Excellent')
  • )

Make a randomized survey design

design <- cbc_design(

  • profiles = profiles,
  • n_resp = 300, # Number of respondents
  • n_alts = 3, # Number of alternatives per question
  • n_q = 6 # Number of questions per respondent
  • )

Simulate random choices

data <- cbc_choices(

  • design = design,
  • obsID = "obsID"
  • )

Conduct a power analysis

power <- cbc_power(

  • data = data,
  • pars = c("price", "type", "freshness"),
  • outcome = "choice",
  • obsID = "obsID",
  • nbreaks = 10,
  • n_q = 6
  • )
    Estimating models using 3 cores...
    done!

head(power)
sampleSize coef est se
1 30 price NA NA
2 30 typeGala NA NA
3 30 typeHoneycrisp NA NA
4 30 freshnessAverage NA NA
5 30 freshnessExcellent NA NA
6 60 price NA NA
tail(power)
sampleSize coef est se
45 270 freshnessExcellent NA NA
46 300 price NA NA
47 300 typeGala NA NA
48 300 typeHoneycrisp NA NA
49 300 freshnessAverage NA NA
50 300 freshnessExcellent NA NA


Any other thoughts | ideas?

Regards --

Steve P.

@STEVEAP28
Copy link
Author

STEVEAP28 commented Mar 7, 2023 via email

@jhelvy
Copy link
Owner

jhelvy commented Mar 7, 2023

I'm at a bit of a loss here. I've ran the same code on multiple machines, never getting NA values.

Can you run sessionInfo() on your machine and copy over what is printed out? My only guess is that you have a version issue somewhere, perhaps some dependency that isn't updated?

This shouldn't be a problem as cbcTools should update all needed packages when installing, but perhaps I have an error in there somewhere.

@STEVEAP28
Copy link
Author

STEVEAP28 commented Mar 7, 2023 via email

@jhelvy
Copy link
Owner

jhelvy commented Mar 7, 2023

Okay this all looks good. The only thing slightly out of date is the R version, but it shouldn't be an issue. Maybe try updating to the latest R? I can't imagine that would change anything though.

My only other suggestion at this point is to perhaps screen record yourself walking through this example and post it on youtube. Maybe I'll catch something watching it run on your machine.

But really I'm stuck if I can't get the error to occur. The fact that it runs without NAs on the colab notebook suggests that the issue is probably something on your machine specifically (e.g. an outdated package). But even that looks okay based on the list I'm seeing here.

@STEVEAP28
Copy link
Author

STEVEAP28 commented Mar 7, 2023 via email

@jhelvy
Copy link
Owner

jhelvy commented Mar 7, 2023

Fantastic! Really glad we figured out the dependency issue. That said, this is still concerning as the packages should be updated upon installing the package with install.packages('cbcTools'). So I'll have to take a look at what's going on there.

As for the differences, I'll take a look as well to see if I can figure out the source of the issue. Can you post your SE results here?

@STEVEAP28
Copy link
Author

STEVEAP28 commented Mar 7, 2023 via email

@jhelvy
Copy link
Owner

jhelvy commented Mar 7, 2023

More mysteries to solve...once again tricky as I am getting the same values on my local machine as those in the colab notebook.

So once again I suspect there is a very small difference between our system configurations leading to slight differences. Given how small the differences are though, I suspect this is the result of a difference in the random number generator. It may be that the same seed produces slight differences depending on the version of R you're using, or perhaps some other package. All that said, I'm not too concerned here as these results are quite similar.

I do, however, need to update the package DESCRIPTION file to make sure the appropriate dependencies are in place. Can you tell / do you remember which specific packages you updated? If so, I can force a minimum version so that when users install {cbcTools} the appropriate dependencies are installed with it.

@STEVEAP28
Copy link
Author

STEVEAP28 commented Mar 7, 2023 via email

@jhelvy jhelvy closed this as completed May 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants