使用具有不同间隔/滞后的数据进行线性回归

Working with data that has different intervals/lags for linear regression

提问人:Simba 提问时间:11/9/2023 最后编辑:PhilSimba 更新时间:11/9/2023 访问量:22

问:

我正在处理卫星数据并比较两个变量以进行线性回归。Y 变量有 3 天的滞后,而 X 变量有 5 天的滞后,创建散点图时,它主要显示为空,数据随机排列,并非所有点都被表示。问题可能出在具有不同滞后的数据上吗?我附上了我一直在使用的代码。你能帮忙吗?

enter image description here

# Install and load necessary libraries
install.packages("readr")  # For reading CSV data
install.packages("ggplot2")  # For visualization
install.packages("lmtest")  # For regression analysis
library(readr)
library(ggplot2)
library(lmtest)


data <- read.csv("C:/Users/WINDOWS 10/Desktop/desktop/Masters Doc/Results/R/SCL KNDVI and Soil moisture.csv")

# Remove rows with missing values
data <- na.omit(data)

# Summary statistics
summary (data)

# Scatter plot
ggplot(data, aes(x = SCLKNDVI, y = SCLSoil.moisture)) +
  geom_point() +
  labs(x = " SCLKNDVI", y = "SCLSoil.moisture") +
  ggtitle("Scatter Plot of SCLKNDVI vs. Soil Moisture")

# Perform linear regression
regression_model<- lm(SCLSoil.moisture ~ SCLKNDVI, data = data)

# Summary of the regression model
summary(regression_model)

# Scatter plot with regression line
# Scatter plot
ggplot(data, aes(x =SCLKNDVI , y =  SCLSoil.moisture)) +
  geom_point() +
  labs(x = "SCLKNDVI", y = "SCLSoil.Moisture") +
  ggtitle("Scatter Plot of KNDVI vs. Soil Moisture")

表格链接

我尝试执行 NA 省略数据,它有效,但是如果我处理的数据有很多滞后,它不会扭曲线性回归的结果吗?我期待在散点图中显示大部分数据点的图形。

r 线性回归 散点图

评论


答: 暂无答案