Curve fitting in R curve fitting with least squares fitting

Source: Internet
Author: User
Curve fitting: (Linear regression method: LM)1, x order 2, the linear regression equation and give a new variable Z=LM (y~x+i (x^2) + ...) 3, Plot (x,y) #做y对x的散点图 4, lines (x,fitted (z)) #添加拟合值对x的散点图并连线
curve Fitting: (NLS)LM is to line up the curve and do regression, the NLS is a direct fitting curve. Three conditions are required: The curve equation, the data position, and the estimated value of the coefficients. If the curve equation is more complex, you can first name a custom function.     Example: F=function (x1, x2, A, b) {a+x1+x2^b};         Result=nls (X$y~f (x$x1, x$x2, A, b), Data=x, Start=list (A=1, b=2));    #x可以是数据框或列表, but can not be a matrix #对系数的估计要尽量接近真实值, if the difference is too far will be an error: "Singular gradient" summary (result); #结果包含对系数的估计和p值 the lines curve can be used directly on the scatter chart according to the estimated coefficients.
curve fitting: (partial regression)Lowess (x, y=null, F = 2/3, iter = 3) #可以只包含x, you can also use X, y two variables #f为窗宽参数, the larger the smoother #iter为迭代次数, the greater the calculation the slower loess (y~x, data, span =0.75, degree=2) #data为包含x, y data sets, span for window width parameters #degree默认为二次回归 #该方法计算1000个数据点约占10M内存 Examples: x=seq (0, 10, 0.1);    Y=sin (x) +rnorm (a) #x的值必须排序 plot (x,y);    #做散点图 lines (lowess (x,y));    #利用lowess做回归曲线 lines (X,predict (loess (y~x)); #利用loess做回归曲线, the Predict is z=loess (y~x) with regression prediction value.    Lines (x, Z$fit); #利用loess做回归曲线的另一种做法

Welcome Exchange: QQ279175732 specializes in the field: indoor positioning, navigation algorithms, data analysis and data mining

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.