Menu

trouble with crosstabs and regression output

Help
edoviak
2007-10-08
2013-01-15
  • edoviak

    edoviak - 2007-10-08

    Just installed the latest version of RKWard on Debian Etch/Lenny (architecture: i686). Once again, I'm very impressed by the progress the developers have made. Thank you for all of your hard work on this project.

    As I was looking at some of the new features -- Crosstabs and Linear Regression -- I ran into some trouble and I'm wondering if there's a simple remedy that I missed.

    Specifically, when I try to run Crosstabs, I load the "xtable" and "R2HTML" packages (as instructed). After I load those packages and try again, I get the following error message:

    Error in eval.with.vis(expr, pf, baseenv()) :
            could not find function "print.xtable"
    In addition: Warning message:
    Chi-squared approximation may be incorrect in: chisq.test(results[[i]], simulate.p.value = FALSE)

    Is there another package I need to load in order to view the output? Linear regression runs much better, but the significance codes look funny (at least on my computer):

    --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

    Is there a font that I need to install or something?

    Thanks,
    - Eric

     
    • nono_231

      nono_231 - 2007-10-09

      Hi edoviak!

      Thanx for the good words!

      The crosstabs N to 1 plugin:
      The problem already discovered just a few days after the release unfortunately. It is a problem that came up from the combination of rk.print and xtable, which for an undefined reason does not work anymore. We searched all the plugins (but we missed this one - hopefully the only one) to fix it using rk.results instead of rk.print before the release. Unfortunately there is not much that you can do. A next bug fix release can solve the problem.

      The linear regression plugin:
      It is a problem of encoding. I wrote a much more elaborate version of lr plugin in order to avoid this problem, but did not pass. I suggest to the main developer to go back to this version (and solve any problems that may come up).
      This is something you can do for this for now. When you are at the results tab you can cange manually to utf-8 (from the view menu). That will solve the problem temporarily.

      Thanx for the reports.

      Kind Regards,
      Ilias

       
    • edoviak

      edoviak - 2007-10-09

      Thanks for the quick response.

      The linear regression output is perfect with the UTF-8 encoding.

      As regards crosstabs ... Your suggestion to replace "rk.print" with "rk.results" works ... well, sort of. The output table is very confusing if you're using dummy variables. For example, create a fictional dataset with two dummy variables: RKWard_user (1 if uses RKWard, 0 otherwise) and female (1 if female, 0 otherwise). Then run the N to 1 crosstab and look at the output.

      From another test, I know that the independent variable is in the columns and the dependent variable is in the rows, but there are no labels beside the rows and above the columns, so it's very confusing when you're working with two dummy variables. I know this is easier said than done, but ... would it be possible to add labels in the next version of RKWard?

      If it helps you, I'll fiddle with the R script to create the labels. (Sorry. I don't know PHP).

      On a positive note ... You gave me a Chi-Square statistic and a p-value. That makes me happy!

      Thanks again,
      - Eric

       
      • Thomas Friedrichsmeier

        Hi Eric,

        > If it helps you, I'll fiddle with the R script to create the labels. (Sorry. I don't know PHP).

        sorry, I got a bit distracted by the KDE 4 porting efforts, but certainly not turning down an offer for help.

        If you could look into the R code in this respect, that would be great. Probably the most useful way would be to extend rk.results() so that it can generally handle tables and matrices in a sensible way, as this sort of results will probably come up in several plugins.

        If you come up with anything, please post to the rkward-devel mailing list (postings by non-members are moderated due to problems with SPAM, not to actually restrict who can post).

        Regards
        Thomas

         
    • edoviak

      edoviak - 2007-11-16

      Hi Thomas and RKWard Developers,

      I found a simple way to use R code to create the labels for any number of independent variables and any number of values. I sent the R script and the test dataset to the rkward-devel mailing list. Hopefully, it will pass through the spam filter. Let me know if it does not. 

      Thanks again!
      - Eric

       
      • Thomas Friedrichsmeier

        Hi Eric,

        that's great news. I'm looking forward to your script. Unfortunately, if you already sent it, it seems to have gone lost in some filter, indeed. Could you resend?

        Thanks!
        Thomas

         
    • edoviak

      edoviak - 2007-11-18

      Here's the message I sent to rkward-devel [at] lists [dot] sourceforge [dot] net

      Is that the correct address? I'll also try resending it. Apologies in advance if you get it a few times.

      - Eric

      -------------------

      Hi Thomas and RKWard Developers,

      Last month, I promised to create labels for the output of the  crosstabs (N to 1) plugin. Apologies for being a bum.

      On a positive note, I found a simple way to use R code to create the labels. Below this message is the text of the R script and the simple comma-separated value dataset that I used to test the script.

      Since a month has passed ... Here's a summary of the bug that this script fixes: In the current version of RKWard (0.4.8a), the output table of the crosstabs (N to 1) plugin is very confusing. For example, create a fictional dataset with two dummy variables: RKWard_user (1 if uses RKWard, 0 otherwise) and female (1 if female, 0 otherwise). Then run the N to 1 crosstab and look at the output. The only labels on the rows and columns are 0 and 1.

      The script below adds labels to the rows and columns of the output table. It can handle any number of independent variables and any number of values.

      I hope this small contribution helps. Let me know if you have any questions.

      Thanks again for producing a great product!
      - Eric

      local({
      ## Prepare
      ## Compute
      x <- my.csv.data[["white"]]
      yvars <- list (substitute (my.csv.data[["gray"]]), substitute (my.csv.data[["black"]]))
      results <- list()
      descriptions <- list ()

      # calculate crosstabs
      for (i in 1:length (yvars)) {
         yvar <- eval (yvars[[i]], envir=globalenv ())
         results[[i]] <- table(x, yvar)

         descriptions[[i]] <- list ('Dependent'=rk.get.description (my.csv.data[["white"]]), 'Independent'=rk.get.description (yvars[[i]], is.substitute=TRUE))
      }

      ## make row and column names
      nu_dep     <- c( rep( NA , times=length( results ) ) )
      nu_indep   <- c( rep( NA , times=length( results ) ) )

      dep_dim_names    <- c( rep( NA , times=length( results ) ) )
      indep_dim_names  <- c( rep( NA , times=length( results ) ) )

      for (i in 1:length( results ) ) {
             nu_dep[i]     <- length( row.names(   results[[i]]  ) )
             nu_indep[i]   <- length( row.names( t(results[[i]]) ) )

             dep_name   <- c( rep( NA , times = nu_dep[i]   ) )
             indep_name <- c( rep( NA , times = nu_indep[i] ) )

             for (j in 1:nu_dep[i]) {
               dep_name[j]   <- as.character( paste( descriptions[[i]][['Dependent']], "=", row.names( results[[i]] )[j] , ": " ) )         }

             for (j in 1:nu_indep[i]) {
               indep_name[j]   <- as.character( paste( descriptions[[i]][['Independent']],"=", row.names( t( results[[i]] ) )[j] , ": " ) )
             }

             dep_dim_names[i]   <- list(dep_name)
             indep_dim_names[i] <- list(indep_name)
      }

      ## Print result
      for (i in 1:length (results)) {
          rk.header ("Crosstabs (n to 1)", parameters=list ("Dependent", descriptions[[i]][['Dependent']], "Independent", descriptions[[i]][['Independent']]))
         rk.print (as.data.frame( matrix( results[[i]] , nrow=nu_dep[i] , ncol=nu_indep[i]  ,
                    dimnames= list( dep_dim_names[i][[1]] , indep_dim_names[i][[1]] ) ) ) )
      }
      })

      black,white,gray
      2,3,1
      0,3,3
      1,1,1
      0,2,2
      1,2,4
      0,0,1
      1,0,2
      0,0,1
      2,0,1
      0,0,4
      1,1,1
      0,1,2
      2,1,1
      0,1,2
      1,1,1
      0,0,2
      2,1,0
      0,0,0
      1,0,0
      2,0,3
      1,1,0
      0,1,0
      1,1,3
      0,1,0
      1,1,0
      1,0,0
      1,1,0
      1,0,3
      1,0,4
      0,0,0

       
      • Thomas Friedrichsmeier

        Hi,

        > Here's the message I sent to rkward-devel [at] lists [dot] sourceforge [dot] net 
        >
        > Is that the correct address? I'll also try resending it. Apologies in advance if you get it a few times.

        that's strange. This is the correct address, indeed, but once again it seems to have been lost, somewhere (and I have no idea, where. Did you receive any "your message is being held" notifications or the like?). I did receive the mail you sent to my @users.sourceforge.net-address, directly.

        > The script below adds labels to the rows and columns of the output table. It can handle
        > any number of independent variables and any number of values.
        >
        > I hope this small contribution helps. Let me know if you have any questions.

        It really did help. In the end I decided to approach the problem slightly differently, by moving the logic (in somewhat modified form) into rk.results() itself (I did so, as I felt, printing 2d tables might be needed at other places as well, in the future). But having an existing working solution to look at certainly helped in doing that. So thanks a lot.

        If you're following SVN (http://rkward.sourceforge.net/wiki/index.php?title=RKWard_SVN), you can have a look already (you'll need to make install, again, to install the new rk.results() function), and test whether it works in all cases you have tested your solution in.

        Regards
        Thomas