Hello, I would like to get a correlation coefficient (R-squared) for my model. I don't know how to calculate it in R. What I've done so far: x<-8.5:32.5 #Vektor x y<-c(NA ,5.88 , 6.95 , 7.2 , 7.66 , 8.02 , 8.44 , 9.06, 9.65, 10.22 , 10.63 ,11.06, 11.37, 11.91 ,12.28, 12.69 ,13.07 , 13.5 , 13.3 ,14.14 , NA , NA , NA , NA , NA) #Vektor y plot(y~x,col="green",pch=16,ylim=c(0,20),xlim=c(0,50)) (mod1<-nls(y~a+b*log(x,base=exp(1)),start=list(a=1,b=1),trace=TRUE)) xx<-seq(min(x),max(x),length=100) yy<-6.2456*log(xx)-7.7822 lines(xx,yy,col="blue1") summary(mod1) This way I don't get R-squared like I do using the command "lm" for linear models. Would appreciate your help, Benedikt N. --
>>>>> "BN" == Benedikt Niesterok <KleinerHaifisch at gmx.net> >>>>> on Tue, 28 Apr 2009 15:33:02 +0200 writes:BN> Hello, BN> I would like to get a correlation coefficient (R-squared) for my model. {{ arrrgh... how many people think they "need" an R^2 when they fit a model ?? }} BN> I don't know how to calculate it in R. BN> What I've done so far: BN> x<-8.5:32.5 #Vektor x BN> y<-c(NA ,5.88 , 6.95 , 7.2 , 7.66 , 8.02 , 8.44 , 9.06, 9.65, 10.22 , BN> 10.63 ,11.06, 11.37, 11.91 ,12.28, 12.69 ,13.07 , 13.5 , 13.3 ,14.14 , NA , NA , NA , NA , NA) #Vektor y BN> plot(y~x,col="green",pch=16,ylim=c(0,20),xlim=c(0,50)) BN> (mod1<-nls(y~a+b*log(x,base=exp(1)),start=list(a=1,b=1),trace=TRUE)) This is a very *LINEAR* model. Why don't you use lm()? Then you'd even get your beloved R-squared ... BN> xx<-seq(min(x),max(x),length=100) BN> yy<-6.2456*log(xx)-7.7822 BN> lines(xx,yy,col="blue1") BN> summary(mod1) BN> This way I don't get R-squared like I do using the command "lm" for linear BN> models. In general, R^2 is *NOT* easily defined for non-linear models. R^2 is only defined if you have a nested sub-model, aka "null-model". For linear models (*WITH* an intercept (!)), the sub-model is naturally y ~ 1. For general nonlinear models, the only simple sub-model is 'y ~ 0' which is often ridiculous to take as null-model, and hence not taken by default. More more on this, e.g. almost 7 years ago on R-help: https://stat.ethz.ch/pipermail/r-help/2002-July/023461.html Martin
Dieter Menne <dieter.menne at menne-biomed.de> wrote>I noted the "and" was misleading. Read: Good journals like Lancet, >New English and many British Journal of XXX really help you to do >better.I am one of the statistical editors for PLoS Medicine, and I try to help people do better; often, the people take my advice. Sometimes, they don't. I get good support from the editorial people there. Peter Peter L. Flom, PhD Statistical Consultant www DOT peterflomconsulting DOT com
Apparently Analagous Threads
- Comparing 2 slopes of 2 regression lines
- read.table but more tables at once
- Operations with long altrep vectors cause segfaults on Windows
- Problem with a defined function which cannot access a function defined outside of the function
- [External] Re: Operations with long altrep vectors cause segfaults on Windows