Spearman correlation fails in ranking strings
    5 visualizzazioni (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    
    federico nutarelli
 il 11 Gen 2022
  
    
    
    
    
    Risposto: Jeff Miller
      
 il 11 Gen 2022
            Hi all,
I would like to compute the correlation between two rankings. Namely, I have two ranked variables, say:
table GDP
ln_gdp             country1
6.62273632394984	'BURUNDI'
6.96602418710611	'MALAWI'
7.00124562206948	'DR CONGO'
7.15539630189673	'MOZAMBIQUE'
7.36518012602101	'CHAD'
and  a money2 table:
money              country2
0.0871934820000000	'MALAWI'
0.123754360000000	'DR CONGO'
0.193845570000000	'CHAD'
0.230036880000000	'BURUNDI'
0.264654610000000	'MOZAMBIQUE'
Now simply I would like to compare the two variables ranked country1 and country2 as:
corr(money2.country2, GDP.country1'type','Spearman');
but the following error occurs:
Check for missing argument or incorrect argument data type in call to function 'imag'.
Error in corr (line 192)
complexdata = ~(isreal(x) || all(imag(x(:))==0));
what am I doing wrong?
P.s. the rownames are the names of the country.
Thank you
0 Commenti
Risposta accettata
  Jeff Miller
      
 il 11 Gen 2022
        The first two inputs to the corr command have to be the numerical values that are to be correlated, so you will want something like
corr(money2.money,GDP.ln_gdp,...)
However, you have to make sure that the rows of the two tables correspond (e.g., first row of each table has BURUNDI, second row has  CHAD, etc).  Maybe you can do that with sortrows()
0 Commenti
Più risposte (0)
Vedere anche
Categorie
				Scopri di più su Tables in Help Center e File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!