Coder Social home page Coder Social logo

Comments (3)

philchalmers avatar philchalmers commented on May 23, 2024

Whenever you use the c() operator R will coerce the provided elements to the most general type. So, c(1.2, 1, TRUE), will change TRUE to the value 1.0. Consider what happens when you pass this c(1,2,'a').

If you want to keep the types constant return a data.frame() in your Analyse() step. That will allow the column elements to be of different type. Just change

ret <- c(coefficientInt=coef(summary(fit))[4,1], singular=singular)

to

ret <- data.frame(coefficientInt=coef(summary(fit))[4,1], singular=singular)

from simdesign.

kneijenhuijs avatar kneijenhuijs commented on May 23, 2024

Thanks, I feel silly for not catching that. However, I still run into issues when including a Boolean vector in the returned data frame from the Analyse function. When I implement your suggestion, I run into the following error code and traceback:

 Error in FUN(X[[i]], ...) : 
  only defined on a data frame with all numeric variables 
7.
stop("only defined on a data frame with all numeric variables") 
6.
FUN(X[[i]], ...) 
5.
lapply(args, function(x) {
    x <- as.matrix(x)
    if (!is.numeric(x) && !is.complex(x)) 
        stop("only defined on a data frame with all numeric variables") ... 
4.
Summary.data.frame(structure(list(singular = c(FALSE, FALSE, 
TRUE, TRUE, FALSE)), row.names = c(NA, -5L), class = "data.frame"), 
    na.rm = TRUE) 
3.
Functions$summarise(results = results, condition = condition, 
    fixed_objects = fixed_objects) 
2.
Analysis(Functions = Functions, condition = design[i, ], replications = replications, 
    fixed_objects = fixed_objects, cl = cl, MPI = MPI, seed = seed, 
    bootSE = bootSE, boot_draws = boot_draws, save = save, save_results = save_results, 
    save_results_out_rootdir = out_rootdir, save_results_dirname = save_results_dirname,  ... 
1.
runSimulation(Design, replications = 5, verbose = FALSE, parallel = FALSE, 
    generate = Generate, analyse = Analyse, summarise = Summarise, 
    progress = TRUE) 

The issue seems to occur with step 5, which I assume is part of the Summary.data.frame type. I have fixed my issue for now by transforming my boolean into a vector of zeroes and ones (so that I can still easily sum up the counts of TRUE), but it seems that there are issues with returning values that are not numeric.

from simdesign.

philchalmers avatar philchalmers commented on May 23, 2024

In your runSimulation() call, try using the edit option for debugging. This will step into the respective function so you can play around with the state of the objects directly so that you can see what's going on. When I do this:

runSimulation(..., edit = 'summarise')

I see that

Browse[2] > str(results)
'data.frame':	5 obs. of  2 variables:
 $ coefficientInt: num  1.04 -0.585 0.803 -0.383 -0.327
 $ singular      : logi  FALSE FALSE FALSE FALSE FALSE

So, results is a data.frame object with 2 columns. Running the next line bias(results[1]) doesn't work because data.frames should be indexed either by column (results[,1]), the $ sign (results$coefficients), or lists (results[[1]]). Therefore, all you need to change is the [#] components to [[#]] to fix your code. HTH.

from simdesign.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.