this is, I think, an easy question... I did a regression analysis in R, where I wanted to check the fit of my data to a specific formula I provided... I got this to work, I see the graph and the line showing the fit of the data, but I also would like to get actual regression value obtained from this calculation, how do I do this? and How do I get the actual equation printed in the graph?
Hi thanks a lot for the replies.
The example was very useful, but I still didnt obtain the Regression value, so I still dont know how well my data fits the equation... below Im pasting the code I used
# import the input data file "LD251-chilR.txt", for the input; # the first column is pairwise distance and the second is LD estimate, # need to put the file in the same folder with R program CT251chil<-read.table("LD251-chilR.txt", sep="\t", dec=",", header=TRUE) # your LD estimate (r2 in this case which located in column 2) r2=CT251chil[,2] # run nls function for getting rho estimate nls(r2~1/(1+rho*CT251chil[,1]), start=list(rho=0.3)) # getting this rho estimate after running nls function in R rho=0.02206872 #sort the data, no need if your data already sorted dist<-sort(CT251chil[,1]) # put parameters in the equation as shown in my MBE paper eq <- (((10+rho*dist)/((2+rho*dist)*(11+rho*dist)))*(1+((3+rho*dist)*(12+12*rho*dist+(rho*dist)^2)/(46*(2+rho*dist)*(11+rho*dist))))) # plotting the graph between LD estimate and distance plot(CT251chil[,1],CT251chil[,2], col="black", pch=20, ylab=expression(R^2), xlab="Pairwise distance", main="CT251-chilense", las=1) # getting regression line lines(dist,eq, col="black",lwd=2,lty=1)
After this point I get a graph with a line, all good. But so far I dont know how to output the actual equation on the graph get the value of R.
thank you for any further help!