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

  • SEARCH
  • Home
  • 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 6544645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:29:26+00:00 2026-05-25T11:29:26+00:00

I was running discriminant analysis using R. The code is the following: fit <-

  • 0

I was running discriminant analysis using R. The code is the following:

fit <- lda(group~ A+C1_1+C2+D1a_1+D2_1+D3_1+D3_2+D3_3+E1a_1+E1b_1+E1b_2+E2_1+E3_1+E3_2+E3_3+F2+G_1+G_2+G_3+G_4+H1_1+H2a_1+H2b_1+H3_1+H4_1_1+H1_2+H2a_2+H2b_2+ H3_2+H4_1_2+J1_1+J2_1+J3_1+K1a+K2_1+K2_2+K2_3+K2_4,data=data1)

But unfortunately I was getting the following error:

Error in x - group.means[g, ] : non-conformable arrays

This is the str(data1) output:

'data.frame':   210 obs. of  133 variables:

 $ A               : int  1 1 1 1 1 1 1 2 1 2 ...

 $ C1_1            : int  22 29 12 12 25 15 30 20 30 15 ...
 $ C2              : int  2 2 2 2 2 2 2 1 2 2 ...
 $ D1a_1           : int  40 50 160 15 150 105 150 45 100 80 ...
 $ D2_1            : int  100 100 100 100 100 100 100 90 95 100 ...
 $ D3_1            : int  5 15 40 10 30 25 30 40 25 60 ...
 $ D3_2            : int  10 30 30 15 30 25 60 40 20 10 ...
 $ D3_3            : int  10 30 30 10 10 15 10 20 20 30 ...
 $ E1a_1           : int  80 25 140 30 150 120 80 30 100 100 ...
 $ E1b_1           : int  100 50 50 25 80 70 80 75 10 75 ...
 $ E1b_2           : int  0 50 50 75 20 30 20 25 90 25 ...
 $ E2_1            : int  20 60 75 70 60 80 75 100 60 80 ...
 $ E3_1            : int  5 20 20 5 30 20 25 25 10 30 ...
 $ E3_2            : int  10 20 40 15 30 20 50 50 10 30 ...
 $ E3_3            : int  10 20 15 10 10 20 25 25 10 40 ...
 $ G_1             : int  5 50 20 25 80 10 30 25 35 5 ...
 $ G_2             : int  0 10 50 50 10 10 30 30 30 10 ...
 $ G_3             : int  90 30 20 25 10 50 5 30 15 80 ...
 $ G_4             : int  5 10 10 0 0 30 35 15 20 5 ...
 $ H1_1            : int  1 3 3 2 3 2 3 3 2 3 ...
 $ H2a_1           : int  NA NA NA 1 NA 2 NA NA 1 NA ...

 $ H2b_1           : int  NA 2 1 NA 2 NA 1 1 NA 1 ...

 $ H3_1            : int  2 2 2 2 2 3 3 3 2 2 ...

 $ H4_1_1          : int  6 5 7 6 3 6 5 6 5 5 ...

 $ J1_1            : int  4 6 4 4 4 4 6 7 3 3 ...
 $ J2_1            : int  2 6 5 3 4 4 1 2 3 3 ...
 $ J3_1            : int  4 5 3 3 4 4 6 7 3 4 ...

 $ K1a             : int  2 2 2 2 2 2 2 2 1 1 ...

 $ K2_1            : int  NA NA NA NA NA NA NA NA 0 0 ...
 $ K2_2            : int  NA NA NA NA NA NA NA NA 1 0 ...
 $ K2_3            : int  NA NA NA NA NA NA NA NA 0 1 ...
 $ K2_4            : int  NA NA NA NA NA NA NA NA 0 0 ...

  [list output truncated

]]

Second, can anybody please tell me how to get the significance level of the variables used in the discriminant analysis.

  • 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-25T11:29:27+00:00Added an answer on May 25, 2026 at 11:29 am

    Works fine with a randomly generated data set with no NA values:

    set.seed(101)
    z <- matrix(runif(210*133),nrow=210)
    zz <- data.frame(A=sample(1:2,size=210,replace=TRUE),z)
    m <- MASS::lda(A~.,data=zz)
    

    I can reproduce the error if I add enough NAs:

    z2 <- z
    z2[sample(length(z),size=2000)] <- NA
    zz2 <- data.frame(A=sample(1:2,size=210,replace=TRUE),z2)
    m <- MASS::lda(A~.,data=zz2)
    

    results in

    Error in x - group.means[g, ] : non-conformable arrays
    

    (if I knock out fewer I get warnings about collinearity instead)

    For a start, try removing all variables with any NA values (or those with more than a few) and see if you can get it to work.

    For the p value part of the question: googling “+r MASS lda discriminant analysis” leads to http://www.statmethods.net/advstats/discriminant.html and suggests (and provides a link to) MANOVA for these p values.

    Based on a little bit of googling, it looks like people usually use MANOVA with Wilks’ lambda for tests in the context of LDA: for example, http://userwww.sfsu.edu/~efc/classes/biol710/discrim/discrim.pdf says

    Discriminant function analysis is broken into a 2-step process: (1) testing
    significance of a set of discriminant functions, and; (2) classification. The first
    step is computationally identical to MANOVA.

    They go on to show an example of using Wilks’ lambda, although ?manova says that the Pillai-Bartlett test (which is the default in manova) may be better … in any case, it’s pretty easy to do the test.

    > summary(manova(z~zz$A),test="Wilks")
               Df   Wilks approx F num Df den Df Pr(>F)
    zz$A        1 0.38164  0.92587    133     76 0.6545
    Residuals 208     
    

    This of course is not exactly what you asked for — you asked (I think) for the significance level associated with individual variables rather than with the overall test. I can imagine you could do something via appropriately multiplicity-corrected logistic regression, but this is turning into a statistical rather than an R question. If you don’t get any further answers here you might consider asking an appropriately reformulated question on http://stats.stackexchange.com , referencing this question …

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

Sidebar

Related Questions

I'm trying to conduct a discriminant analysis and keep running into the following error:
Running the following JavaScript code shows 63 in both cases: alert( 0xff >> 2
Running Nh 3.2 using SQLite throws the following exception: ---> NHibernate.HibernateException: Could not create
Running the following code in Delphi XE2 Win32 platform works. However, the same code
Running the following code on Windows 7 x64 #include <stdio.h> #include <errno.h> int main()
Running the following (slightly pseudo)code produces the following results. Im shocked at how innacurate
Running a rails site right now using SQLite3. About once every 500 requests or
Running FxCop on my code, I get this warning: Microsoft.Maintainability : 'FooBar.ctor is coupled
Running an ASP.Net website and using TinyMCE for content management. Users need to be
Now that Apple is running some kind of static analysis to automatically check for

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.