溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

R語言分段回歸數(shù)據(jù),分析案例報告

發(fā)布時間:2020-07-22 21:51:47 來源:網(wǎng)絡(luò) 閱讀:931 作者:nineteens 欄目:編程語言

  # 讀取數(shù)據(jù)

  data=read.csv("artificial-cover.csv")

  # 查看部分數(shù)據(jù)

  head(data)

  ## tree.cover shurb.grass.cover

  ## 1 13.2 16.8

  ## 2 17.2 21.8

  ## 3 45.4 48.8

  ## 4 53.6 58.7

  ## 5 58.5 55.5

  ## 6 63.3 47.2

  #######先調(diào)用spline包

  library ( splines )

  ###########用lm擬合,主要注意部分是bs(age,knots=c(...))這部分把自變量分成不同部分

  fit =lm(tree.cover~bs(shurb.grass.cover ,knots =c(25 ,40 ,60) ),data=data )

  ############進行預測,預測數(shù)據(jù)也要分區(qū)

  pred= predict (fit , newdata =list(shurb.grass.cover =data$shurb.grass.cover),se=T)

  #############然后畫圖

  plot(fit)

  # 可以構(gòu)造一個相對復雜的 LOWESS 模型(span參數(shù)取小一些),然后和一個簡單的模型比較,如:

  ## `geom_smooth()` using method = 'loess'

  # 其他數(shù)據(jù)

  data=data[,1:4]

  head(data)

  ## year Soil vegetation SEM

  ## 1 1999 -3.483724 -2.528836 2.681003

  ## 2 1999 -3.452582 -2.418049 2.348640

  ## 3 1999 -3.350827 -2.590552 2.696037

  ## 4 1999 -3.740395 -2.933848 3.627112

  ## 5 1999 -3.465906 -2.694211 2.333755

  ## 6 1999 -3.381802 -2.788154 2.656276

  #####因變量 Soil

  #######先調(diào)用spline包

  library ( splines )

  ###########用lm擬合,主要注意部分是bs(age,knots=c(...))這部分把自變量分成不同部分

  #############然后畫圖

  plot(fit)無錫×××醫(yī)院 https://yyk.familydoctor.com.cn/20612/

  # 可以構(gòu)造一個相對復雜的 LOWESS 模型(span參數(shù)取小一些),然后和一個簡單的模型比較,如:

  library(ggplot2)

  ## `geom_smooth()` using method = 'loess'

  # 總趨勢

  # 按0前后分組

  #####因變量 SEM

  #######先調(diào)用spline包

  library ( splines )

  ###########用lm擬合,主要注意部分是bs(age,knots=c(...))這部分把自變量分成不同部分

  fit =lm(SEM~bs(vegetation ,knots =c(-2 ,0 ,1) ),data=data )

  ############進行預測,預測數(shù)據(jù)也要分區(qū)

  pred= predict (fit , newdata =list(vegetation =data$vegetation),se=T)

  #############然后畫圖

  plot(fit)

  # 可以構(gòu)造一個相對復雜的 LOWESS 模型(span參數(shù)取小一些),然后和一個簡單的模型比較,如:

  x<-data$vegetation

  y<-data$SEM

  # 總趨勢

  ## `geom_smooth()` using method = 'loess'


向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI