[R] Help please
Jim Lemon
drjimlemon at gmail.com
Mon Jun 26 02:29:59 CEST 2017
Hi Rabby,
Before you run your regression, try this:
is.factor(Final$Cor)
If this returns TRUE, then this variable is a factor and it will be
treated as a number of levels rather than a set of numeric values.
This usually happens when a text file is read in and there is at least
one value that cannot be converted to numeric. So if you are doing
something like this:
Final<-read.csv("Final.csv")
Try this:
Final<-read.csv("Final.csv",stringsAsFactors=FALSE)
Final$Cor<-as.numeric(Final$Cor)
If there is at least one NA value in Final$Cor, that is probably what
is causing your problem.
Jim
On Mon, Jun 26, 2017 at 9:38 AM, Sarpong, Rabby <es927716 at ohio.edu> wrote:
> Hello Jim,
>
> Thanks for the response I really appreciate it. I have edited the data over
> and over to correct that. But I am still getting the same results. Is that
> the only way to resolve it please?
>
> -Rabby Sarpong
>
> ________________________________
> From: Jim Lemon <drjimlemon at gmail.com>
> Sent: Sunday, June 25, 2017 3:22:54 AM
> To: Sarpong, Rabby
> Cc: r-help at R-project.org
> Subject: Re: [R] Help please
>
> Hi Rabby,
> It looks to me as though your variable Final$Cor is being treated as a
> factor rather than a numeric value. This may be due to one or more
> non-numeric values occurring in the data that is read in. Also you do
> not have to use the Final$* notation in the formula as you have
> specified the data frame "Final".
>
> Jim
>
>
> On Sun, Jun 25, 2017 at 2:17 AM, Sarpong, Rabby <es927716 at ohio.edu> wrote:
>> Hello,
>>
>>
>> I need some help on a regression I am running please. I am running a
>> multiple regression in R and I am getting weird outputs and would like your
>> help in resolving it.
>>
>> This is the code I run:
>>
>>
>> Reg = lm (Final$Y.t.-Final$Y.t.1. ~ Final$ Y.t.1. + Final$Cor +
>> Final$Gov+ Final$Inv+ Final$TrOp + Final$Pop+ Final$Sch , data = Final)
>> summary(Reg)
>>
>>
>> And the output I get is pasted below. As shown, highlighted variable is
>> regressed more than once which should not be the case and I am not sure why
>> that is the case. I have checked my data and nothing seems out of the
>> ordinary. What could be wrong please?
>>
>>
>> PS. I am still learning to use R.
>>
>>
>> Thank you,
>>
>> Rabby
>>
>>
>>
>> Residuals:
>> Min 1Q Median 3Q Max
>> -1.04279 -0.06739 0.00124 0.06376 1.59115
>>
>> Coefficients:
>> Estimate Std. Error t value Pr(>|t|)
>> (Intercept) 0.1045711 0.0867584 1.205 0.228308
>> Final$Y.t.1. -0.0313686 0.0058536 -5.359 9.95e-08 ***
>> Final$Cor10 0.0009784 0.1622916 0.006 0.995191
>> Final$Cor11 0.1230775 0.1165864 1.056 0.291318
>> Final$Cor12 0.1615939 0.1086529 1.487 0.137199
>> Final$Cor13 0.1934974 0.1160577 1.667 0.095713 .
>> Final$Cor14 0.2341660 0.1286909 1.820 0.069057 .
>> Final$Cor15 0.0744373 0.1036776 0.718 0.472909
>> Final$Cor16 0.1964904 0.0932540 2.107 0.035311 *
>> Final$Cor17 0.1989502 0.0908614 2.190 0.028736 *
>> Final$Cor18 0.1993614 0.0886491 2.249 0.024692 *
>> Final$Cor19 0.2062234 0.0878018 2.349 0.018991 *
>> Final$Cor20 0.1889846 0.0868192 2.177 0.029683 *
>> Final$Cor21 0.1717589 0.0855883 2.007 0.044984 *
>> Final$Cor22 0.1453460 0.0856982 1.696 0.090129 .
>> Final$Cor23 0.1976086 0.0871142 2.268 0.023474 *
>> Final$Cor24 0.1471384 0.0859318 1.712 0.087093 .
>> Final$Cor25 0.1447194 0.0851309 1.700 0.089384 .
>> Final$Cor26 0.1553640 0.0855425 1.816 0.069574 .
>> Final$Cor27 0.1220044 0.0854661 1.428 0.153678
>> Final$Cor28 0.1406044 0.0854213 1.646 0.100011
>> Final$Cor29 0.1594371 0.0860525 1.853 0.064146 .
>> Final$Cor30 0.1792005 0.0863734 2.075 0.038215 *
>> Final$Cor31 0.1376306 0.0871176 1.580 0.114398
>> Final$Cor32 0.1521694 0.0865125 1.759 0.078832 .
>> Final$Cor33 0.1535856 0.0863890 1.778 0.075671 .
>> Final$Cor34 0.1327356 0.0865482 1.534 0.125364
>> Final$Cor35 0.1501163 0.0864312 1.737 0.082661 .
>> Final$Cor36 0.1114404 0.0866389 1.286 0.198587
>> Final$Cor37 0.1326494 0.0873405 1.519 0.129073
>> Final$Cor38 0.0993100 0.0869474 1.142 0.253594
>> Final$Cor39 0.1346916 0.0885424 1.521 0.128458
>> Final$Cor4 0.0306186 0.1625561 0.188 0.850627
>> Final$Cor40 0.1596858 0.0906725 1.761 0.078459 .
>> Final$Cor41 0.1330054 0.0881280 1.509 0.131491
>> Final$Cor42 0.1355948 0.0911754 1.487 0.137216
>> Final$Cor43 0.1106947 0.0921995 1.201 0.230132
>> Final$Cor44 0.1525535 0.0923625 1.652 0.098848 .
>> Final$Cor45 0.0885523 0.0918222 0.964 0.335036
>> Final$Cor46 0.1594086 0.0911042 1.750 0.080406 .
>> Final$Cor47 0.1874162 0.0909010 2.062 0.039435 *
>> Final$Cor48 0.1746566 0.0901044 1.938 0.052800 .
>> Final$Cor49 0.1248750 0.0915038 1.365 0.172592
>> Final$Cor50 0.1270500 0.0900791 1.410 0.158660
>> Final$Cor51 0.0798476 0.0906523 0.881 0.378587
>> Final$Cor52 0.0697894 0.0918425 0.760 0.447468
>> Final$Cor53 0.1632391 0.0930509 1.754 0.079622 .
>> Final$Cor54 0.1143655 0.0933946 1.225 0.220977
>> Final$Cor55 0.0991357 0.0928684 1.067 0.285957
>> Final$Cor56 0.1191313 0.0975565 1.221 0.222257
>> Final$Cor57 0.1288024 0.0939890 1.370 0.170807
>> Final$Cor58 0.1249315 0.0951040 1.314 0.189209
>> Final$Cor59 0.2100375 0.1020216 2.059 0.039723 *
>> Final$Cor60 0.1303076 0.0944493 1.380 0.167937
>> Final$Cor61 0.0928124 0.1056764 0.878 0.379964
>> Final$Cor62 0.0767684 0.1296343 0.592 0.553828
>> Final$Cor63 0.1133221 0.1174685 0.965 0.334879
>> Final$Cor64 0.1412303 0.0978915 1.443 0.149347
>> Final$Cor65 0.1382271 0.1098535 1.258 0.208522
>> Final$Cor66 0.0982404 0.1057428 0.929 0.353041
>> Final$Cor67 0.1893438 0.1022572 1.852 0.064311 .
>> Final$Cor68 0.1578940 0.1634072 0.966 0.334099
>> Final$Cor69 0.2166677 0.1021570 2.121 0.034123 *
>> Final$Cor70 0.1143033 0.1054570 1.084 0.278623
>> Final$Cor71 0.1469311 0.1637571 0.897 0.369757
>> Final$Cor72 0.2268878 0.1103408 2.056 0.039964 *
>> Final$Cor73 0.1925218 0.1055544 1.824 0.068402 .
>> Final$Cor74 0.1574432 0.1020634 1.543 0.123178
>> Final$Cor75 0.0571227 0.1166594 0.490 0.624464
>> Final$Cor76 0.1096049 0.1634571 0.671 0.502635
>> Final$Cor78 0.0949307 0.1305748 0.727 0.467347
>> Final$Cor8 0.1082102 0.1289245 0.839 0.401443
>> Final$Gov -0.0016397 0.0008084 -2.028 0.042736 *
>> Final$Inv 0.0016819 0.0004667 3.604 0.000326 ***
>> Final$TrOp 0.0002904 0.0001209 2.402 0.016445 *
>> Final$Pop -0.0130554 0.0038839 -3.361 0.000799 ***
>> Final$Sch 0.0005785 0.0002696 2.146 0.032064 *
>> ---
>>
>>
>>
>> [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list