[Rd] lm function (PR#13608)
Thomas Lumley
tlumley at u.washington.edu
Wed Mar 18 14:25:55 CET 2009
This is not a bug. You forgot to use the header=TRUE argument to read.table(), so your variables weren't recognized as numeric.
Please don't use r-bugs unless you are sure there is a bug in R. Use r-help to ask for help.
-thomas
On Wed, 18 Mar 2009 michael_karsh at earthlink.net wrote:
> Full_Name: Michael Aaron Karsh
> Version: 2.8.0
> OS: Windows XP
> Submission from: (NULL) (75.61.109.172)
>
>
> I tried using the lm function to regress the third column listed below on the
> second column listed below. It gave me an error message. My code is below.
>
>> HDISWLSdata=read.table("RHDISWLS.txt")
>> HDISWLSdata
> V1 V2 V3
> 1 DENMARK .82 .949
> 2 SWITZERLAND .82 .955
> 3 AUSTRIA .78 .948
> 4 ICELAND .78 .968
> 5 BAHAMAS .77 .845
> 6 FINLAND .77 .952
> 7 SWEDEN .77 .956
> 8 BHUTAN .76 .579
> 9 BRUNEIDARUSSALAM .76 .894
> 10 CANADA .76 .961
> 11 IRELAND .76 .959
> 12 LUXEMBOURG .76 .944
> 13 COSTARICA .75 .846
> 14 MALTA .75 .878
> 15 NETHERLANDS .75 .953
> 16 ANTIGUAANDBARBUDA .74 .815
> 17 MALAYSIA .74 .811
> 18 NEWZEALAND .74 .943
> 19 NORWAY .74 .968
> 20 SEYCHELLES .74 .843
> 21 STKITTSANDNEVIS .74 .821
> 22 UAE .74 .868
> 23 USA .74 .951
> 24 VANUATU .74 .674
> 25 VENEZUELA .74 .792
> 26 AUSTRALIA .73 .962
> 27 BARBADOS .73 .892
> 28 BELGIUM .73 .946
> 29 DOMINICA .73 .798
> 30 OMAN .73 .814
> 31 SAUDIARABIA .73 .812
> 32 SURINAME .73 .774
> 33 BAHRAIN .72 .866
> 34 COLUMBIA .72 .791
> 35 GERMANY .72 .935
> 36 GUYANA .72 .75
> 37 HONDURAS .72 .7
> 38 KUWAIT .72 .891
> 39 PANAMA .72 .812
> 40 STVINCENTANDTHEGRENADINES .72 .761
> 41 UNITEDKINGDOM .71 .946
> 42 DOMINICANREPUBLIC .7 .779
> 43 GUATEMALA .7 .689
> 44 JAMAICA .7 .736
> 45 QATAR .7 .875
> 46 SPAIN .7 .949
> 47 STLUCIA .7 .795
> 48 BELIZE .69 .778
> 49 CYPRUS .69 .903
> 50 ITALY .69 .941
> 51 MEXICO .69 .829
> 52 SINGAPORE .69 .922
> 53 SOLOMONISLANDS .69 .602
> 54 TRINIDADANDTOBAGO .69 .814
> 55 ARGENTINA .68 .869
> 56 FIJI .67 .762
> 57 ISRAEL .67 .932
> 58 MONGOLIA .67 .7
> 59 SAOTOMEANDPRINCIPE .67 .654
> 60 ELSALVADOR .66 .735
> 61 FRANCE .66 .952
> 62 HONGKONG .66 .937
> 63 INDONESIA .66 .728
> 64 KYRGYZSTAN .66 .696
> 65 MALDIVES .66 .741
> 66 SLOVENIA .66 .917
> 67 TAIWAN .66 .925
> 68 EASTTIMOR .66 .514
> 69 TONGA .66 .819
> 70 CHILE .65 .867
> 71 GRENADA .65 .777
> 72 MAURITIUS .65 .804
> 73 NAMIBIA .65 .65
> 74 PARAGUAY .65 .755
> 75 THAILAND .65 .781
> 76 CZECHREPUBLIC .64 .891
> 77 PHILIPPINES .64 .771
> 78 TUNISIA .64 .766
> 79 UZBEKISTAN .64 .702
> 80 BRAZIL .63 .8
> 81 CHINA .63 .777
> 82 CUBA .63 .838
> 83 GREECE .63 .926
> 84 NICARAGUA .63 .71
> 85 PAPUANEWGUINEA .63 .53
> 86 URUGUAY .63 .852
> 87 GABON .62 .677
> 88 GHANA .62 .553
> 89 JAPAN .62 .953
> 90 YEMEN .62 .508
> 91 PORTUGAL .61 .897
> 92 SRILANKA .61 .743
> 93 TAJIKISTAN .61 .673
> 94 VIETNAM .61 .733
> 95 IRAN .6 .759
> 96 COMOROS .59 .561
> 97 CROATIA .59 .85
> 98 POLAND .59 .87
> 99 CAPEVERDE .58 .736
> 100 KAZAKHSTAN .58 .794
> 101 MADAGASCAR .58 .533
> 102 SOUTHKOREA .58 .921
> 103 BANGLADESH .57 .547
> 104 CONGO .57 .548
> 105 GAMBIA .57 .502
> 106 HUNGARY .57 .874
> 107 LIBYA .57 .818
> 108 SOUTHAFRICA .57 .674
> 109 CAMBODIA .56 .598
> 110 ECUADOR .56 .772
> 111 KENYA .56 .521
> 112 LEBANON .56 .772
> 113 MOROCCO .56 .646
> 114 PERU .56 .773
> 115 SENEGAL .56 .499
> 116 BOLIVIA .55 .695
> 117 HAITI .55 .529
> 118 NEPAL .55 .534
> 119 NIGERIA .55 .47
> 120 TANZANIA .55 .467
> 121 BENIN .54 .437
> 122 BOTSWANA .54 .654
> 123 GUINEABISSAU .54 .374
> 124 INDIA .54 .619
> 125 LAOS .54 .601
> 126 MOZAMBIQUE .54 .384
> 127 PALESTINE .54 .731
> 128 SLOVAKIA .54 .863
> 129 BURMA .53 .583
> 130 MALI .53 .38
> 131 MAURITANIA .53 .55
> 132 TURKEY .53 .775
> 133 ALGERIA .52 .733
> 134 EQUATORIALGUINEA .52 .642
> 135 ROMANIA .52 .813
> 136 BOSNIAANDHERZEGOVENIA .51 .803
> 137 CAMEROON .51 .532
> 138 ESTONIA .51 .86
> 139 GUINEA .51 .456
> 140 JORDAN .51 .773
> 141 SYRIA .51 .724
> 142 SIERRALEONE .5 .336
> 143 AZERBAIJAN .49 .746
> 144 CENTRALAFRICANREPUBLIC .49 .384
> 145 MACEDONIA .49 .801
> 146 TOGO .49 .512
> 147 ZAMBIA .49 .434
> 148 ANGOLA .48 .446
> 149 DJIBOUTI .48 .516
> 150 EGYPT .48 .708
> 151 BURKINAFASO .47 .37
> 152 ETHIOPIA .47 .406
> 153 LATVIA .47 .855
> 154 LITHUANIA .47 .862
> 155 UGANDA .47 .505
> 156 ALBANIA .46 .801
> 157 MALAWI .46 .437
> 158 CHAD .45 .388
> 159 IVORYCOAST .45 .432
> 160 NIGER .45 .374
> 161 ERITREA .44 .483
> 162 RWANDA .44 .452
> 163 BULGARIA .43 .824
> 164 LESOTHO .43 .549
> 165 PAKISTAN .43 .551
> 166 RUSSIA .43 .802
> 167 SWAZILAND .42 .547
> 168 GEORGIA .41 .745
> 169 BELARUS .4 .804
> 170 TURKMENISTAN .4 .713
> 171 ARMENIA .37 .775
> 172 SUDAN .36 .526
> 173 UKRAINE .36 .788
> 174 MOLDOVA .35 .708
> 175 ZAIRE .33 .411
> 176 ZIMBABWE .33 .513
> 177 BURUNDI .3
> 178 .413
>> country <- HDISWLSdata[,1]
>> SWLS <- HDISWLSdata[,2]
>> HDI <- HDISWLSdata[,2]
>> HDI <- HDISWLSdata[,3]
>> country
> [1] DENMARK SWITZERLAND AUSTRIA
> ICELAND
> [5] BAHAMAS FINLAND SWEDEN
> BHUTAN
> [9] BRUNEIDARUSSALAM CANADA IRELAND
> LUXEMBOURG
> [13] COSTARICA MALTA NETHERLANDS
> ANTIGUAANDBARBUDA
> [17] MALAYSIA NEWZEALAND NORWAY
> SEYCHELLES
> [21] STKITTSANDNEVIS UAE USA
> VANUATU
> [25] VENEZUELA AUSTRALIA BARBADOS
> BELGIUM
> [29] DOMINICA OMAN SAUDIARABIA
> SURINAME
> [33] BAHRAIN COLUMBIA GERMANY
> GUYANA
> [37] HONDURAS KUWAIT PANAMA
> STVINCENTANDTHEGRENADINES
> [41] UNITEDKINGDOM DOMINICANREPUBLIC GUATEMALA
> JAMAICA
> [45] QATAR SPAIN STLUCIA
> BELIZE
> [49] CYPRUS ITALY MEXICO
> SINGAPORE
> [53] SOLOMONISLANDS TRINIDADANDTOBAGO ARGENTINA
> FIJI
> [57] ISRAEL MONGOLIA SAOTOMEANDPRINCIPE
> ELSALVADOR
> [61] FRANCE HONGKONG INDONESIA
> KYRGYZSTAN
> [65] MALDIVES SLOVENIA TAIWAN
> EASTTIMOR
> [69] TONGA CHILE GRENADA
> MAURITIUS
> [73] NAMIBIA PARAGUAY THAILAND
> CZECHREPUBLIC
> [77] PHILIPPINES TUNISIA UZBEKISTAN
> BRAZIL
> [81] CHINA CUBA GREECE
> NICARAGUA
> [85] PAPUANEWGUINEA URUGUAY GABON
> GHANA
> [89] JAPAN YEMEN PORTUGAL
> SRILANKA
> [93] TAJIKISTAN VIETNAM IRAN
> COMOROS
> [97] CROATIA POLAND CAPEVERDE
> KAZAKHSTAN
> [101] MADAGASCAR SOUTHKOREA BANGLADESH
> CONGO
> [105] GAMBIA HUNGARY LIBYA
> SOUTHAFRICA
> [109] CAMBODIA ECUADOR KENYA
> LEBANON
> [113] MOROCCO PERU SENEGAL
> BOLIVIA
> [117] HAITI NEPAL NIGERIA
> TANZANIA
> [121] BENIN BOTSWANA GUINEABISSAU
> INDIA
> [125] LAOS MOZAMBIQUE PALESTINE
> SLOVAKIA
> [129] BURMA MALI MAURITANIA
> TURKEY
> [133] ALGERIA EQUATORIALGUINEA ROMANIA
> BOSNIAANDHERZEGOVENIA
> [137] CAMEROON ESTONIA GUINEA
> JORDAN
> [141] SYRIA SIERRALEONE AZERBAIJAN
> CENTRALAFRICANREPUBLIC
> [145] MACEDONIA TOGO ZAMBIA
> ANGOLA
> [149] DJIBOUTI EGYPT BURKINAFASO
> ETHIOPIA
> [153] LATVIA LITHUANIA UGANDA
> ALBANIA
> [157] MALAWI CHAD IVORYCOAST
> NIGER
> [161] ERITREA RWANDA BULGARIA
> LESOTHO
> [165] PAKISTAN RUSSIA SWAZILAND
> GEORGIA
> [169] BELARUS TURKMENISTAN ARMENIA
> SUDAN
> [173] UKRAINE MOLDOVA ZAIRE
> ZIMBABWE
> [177] BURUNDI
> 178 Levels: ALBANIA ALGERIA ANGOLA ANTIGUAANDBARBUDA ARGENTINA ARMENIA
> AUSTRALIA AUSTRIA AZERBAIJAN BAHAMAS ... ZIMBABWE
>> SWLS
> [1] .82 .82 .78 .78 .77 .77 .77 .76 .76 .76 .76 .76 .75 .75 .75 .74 .74 .74
> .74 .74 .74 .74 .74 .74 .74 .73 .73 .73 .73
> [30] .73 .73 .73 .72 .72 .72 .72 .72 .72 .72 .72 .71 .7 .7 .7 .7 .7 .7
> .69 .69 .69 .69 .69 .69 .69 .68 .67 .67 .67
> [59] .67 .66 .66 .66 .66 .66 .66 .66 .66 .66 .66 .65 .65 .65 .65 .65 .65 .64
> .64 .64 .64 .63 .63 .63 .63 .63 .63 .63 .62
> [88] .62 .62 .62 .61 .61 .61 .61 .6 .59 .59 .59 .58 .58 .58 .58 .57 .57 .57
> .57 .57 .57 .56 .56 .56 .56 .56 .56 .56 .55
> [117] .55 .55 .55 .55 .54 .54 .54 .54 .54 .54 .54 .54 .53 .53 .53 .53 .52 .52
> .52 .51 .51 .51 .51 .51 .51 .5 .49 .49 .49
> [146] .49 .49 .48 .48 .48 .47 .47 .47 .47 .47 .46 .46 .45 .45 .45 .44 .44 .43
> .43 .43 .43 .42 .41 .4 .4 .37 .36 .36 .35
> [175] .33 .33 .3
> 46 Levels: .3 .33 .35 .36 .37 .4 .41 .42 .43 .44 .45 .46 .47 .48 .49 .5 .51
> .52 .53 .54 .55 .56 .57 .58 .59 .6 ... .82
>> HDI
> [1] .949 .955 .948 .968 .845 .952 .956 .579 .894 .961 .959 .944 .846 .878 .953
> .815 .811 .943 .968 .843 .821 .868 .951
> [24] .674 .792 .962 .892 .946 .798 .814 .812 .774 .866 .791 .935 .75 .7 .891
> .812 .761 .946 .779 .689 .736 .875 .949
> [47] .795 .778 .903 .941 .829 .922 .602 .814 .869 .762 .932 .7 .654 .735 .952
> .937 .728 .696 .741 .917 .925 .514 .819
> [70] .867 .777 .804 .65 .755 .781 .891 .771 .766 .702 .8 .777 .838 .926 .71
> .53 .852 .677 .553 .953 .508 .897 .743
> [93] .673 .733 .759 .561 .85 .87 .736 .794 .533 .921 .547 .548 .502 .874 .818
> .674 .598 .772 .521 .772 .646 .773 .499
> [116] .695 .529 .534 .47 .467 .437 .654 .374 .619 .601 .384 .731 .863 .583 .38
> .55 .775 .733 .642 .813 .803 .532 .86
> [139] .456 .773 .724 .336 .746 .384 .801 .512 .434 .446 .516 .708 .37 .406 .855
> .862 .505 .801 .437 .388 .432 .374 .483
> [162] .452 .824 .549 .551 .802 .547 .745 .804 .713 .775 .526 .788 .708 .411 .513
> .413
> 154 Levels: .336 .37 .374 .38 .384 .388 .406 .411 .413 .432 .434 .437 .446
> .452 .456 .467 .47 .483 .499 .502 ... .968
>> lm(SWLS ~ HDI)
> Error in storage.mode(y) <- "double" :
> invalid to change the storage mode of a factor
> In addition: Warning message:
> In model.response(mf, "numeric") :
> using type="numeric" with a factor response will be ignored
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
Thomas Lumley Assoc. Professor, Biostatistics
tlumley at u.washington.edu University of Washington, Seattle
More information about the R-devel
mailing list