Read the warning message! It has converted your variables into factors. Figure out why...and you will have solved the problem.
Alain Zuur moumita wrote: > > * > * > > Hi , > > Can anyone help me please with this problem?* > * > > *CASE-I* > > all_raw_data_NAomitted is my data frame.It has columns with names i1 ,i2, > i3,i4 , till i15.It has 291 rows actually ,couldnt show here. > > The data frame looks like this:-- > > i1 i2 i3 i4 i5 i6 i7 i8 i9 i10 i11 i12 i13 i14 i15 > > 2 2 2 2 2 2 2 2 2 2 2 1 2 2 3 2 > > 3 2 2 2 2 3 2 2 3 3 3 2 3 3 3 3 > > 4 2 2 2 2 2 2 2 1 1 1 2 1 2 2 2 > > 6 2 2 1 2 1 1 2 2 1 1 1 1 2 2 2 > > 8 3 2 2 2 3 3 3 2 3 2 3 2 3 3 2 > > 9 2 2 2 2 2 2 3 3 3 2 3 3 3 2 2 > > 10 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 > > 12 2 2 2 3 2 2 2 1 3 2 1 2 2 3 3 > > > > While doing regression i1 being the dependent variable and i2 as the > predictor the outputs produced are not correct.The o/ps are as shown > below:--- > > *all_raw_data_NAomitted$i1<-as.vector(as.matrix(all_raw_data_NAomitted$i1)) > all_raw_data_NAomitted$i2<-as.vector(as.matrix(all_raw_data_NAomitted$i2)) > * > > * > * > > *fit<-lrm(i1 ~ i2 + NULL,all_raw_data_NAomitted)* > >> source("regression.R") > > [1] "Printing regression value........................." > > Call: > > lm(formula = i1 ~ i2, data = all_raw_data_NAomitted) > > Residuals: > > Min 1Q Median 3Q Max > > -1.46154 -0.19277 -0.03529 -0.03529 1.96471 > > *Coefficients:* > > * Estimate Std. Error t value Pr(>|t|)* > > *(Intercept) 1.19277 0.05302 22.50 <2e-16 **** > > *i22 0.84252 0.06469 13.03 <2e-16 **** > > *i23 1.52723 0.11021 13.86 <2e-16 **** > > *i24 2.26877 0.14409 15.74 <2e-16 **** > > --- > > Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > > > > Residual standard error: 0.4831 on 287 degrees of freedom > > Multiple R-squared: 0.5815, Adjusted R-squared: 0.5771 > > F-statistic: 132.9 on 3 and 287 DF, p-value: < 2.2e-16 > > > > Error in main() : > > In addition: Warning messages: > > 1: In model.matrix.default(mt, mf, contrasts) : > > variable 'i1' converted to a factor > > 2: In model.matrix.default(mt, mf, contrasts) : > > variable 'i2' converted to a factor > > *The results produced are incorrect and do not match with SPSS results > ,you > can find it out having a look at the coefficients sections of the > result.my > variables were i1 and i2.* > > > > *CASE-II* > > Whereas if I do this the results produced are correct:-- > >> d1<-c(1,2,3,NA,6,7,8) > >> d2<-c(2,3,4,3,1,2,2) > >> d3<-c(2,1,2,1,2,1,3) > >> d4<-c(5,6,2,1,1,2,2) > >> d<-data.frame(d1,d2,d3,d4) > >> d > > d1 d2 d3 d4 > > 1 1 2 2 5 > > 2 2 3 1 6 > > 3 3 4 2 2 > > 4 NA 3 1 1 > > 5 6 1 2 1 > > 6 7 2 1 2 > > 7 8 2 3 2 > >> fit<-lm(d1 ~ d2+d3+d4) > >> summary(fit) > > > > Call: > > lm(formula = d1 ~ d2 + d3 + d4) > > > > Residuals: > > 1 2 3 5 6 7 > > -1.7865 0.9698 -1.2250 -1.4802 1.2761 2.2459 > > > > Coefficients: > > Estimate Std. Error t value Pr(>|t|) > > (Intercept) 9.1912 5.1807 1.774 0.218 > > d2 -0.7570 1.2208 -0.620 0.598 > > d3 0.0151 1.7474 0.009 0.994 > > d4 -0.9842 0.6772 -1.453 0.283 > > > > Residual standard error: 2.692 on 2 degrees of freedom > > (1 observation deleted due to missingness) > > Multiple R-squared: 0.6507, Adjusted R-squared: 0.1267 > > F-statistic: 1.242 on 3 and 2 DF, p-value: 0.4751 > > In case (I) if I make the individual columns as vectors also ,I do not > get > correct results.what could be the cause of the incorrect results produced. > > > -- > Thanks > Moumita > > [[alternative HTML version deleted]] > > > ______________________________________________ > R-help@r-project.org mailing list > 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. > > -- View this message in context: http://www.nabble.com/Regression-function-lm%28%29-not-giving-proper-results-tp24569513p24569838.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help@r-project.org mailing list 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.