0

## 殘差計算

https://drive.google.com/drive/u/1/folders/1_h0tPiYruk59xZSG5Dg5mxW7JskwJV4z

### 1 個回答

0

iT邦大神 1 級 ‧ 2020-06-22 16:43:03

# 使用絕對路徑
#my.stock.df <- read.csv("C:\\it.csv")

my.stock.data.frame <- data.frame(
period = c("2008/1/2","2008/1/3","2008/1/4","2008/1/7","2008/1/8","2008/1/9","2008/1/10"),
stockno = c("1","1","1","1","1","1","1"),
marketrate = rnorm(7),
averagerate = rnorm(7)
)

stock.lm <- lm(averagerate ~ marketrate, data = my.stock.data.frame)

summary(stock.lm)

# 常態性檢定
shapiro.test(stock.lm$residual) # 殘差獨立性檢定 require(car) durbinWatsonTest(stock.lm) # 殘差變異數同質性檢定 require(car) ncvTest(stock.lm)  感謝大大的指導，這是我目前的coding library(dplyr) library(tidyr) library(data.table) library(reshape2) #剔除6642 大盤無 data1 <- fread(file="D:\\it",header=TRUE) data1$市場報酬[is.na(data1$市場報酬)] <- 0 data1$return[is.na(data1$return)] <- 0 fm <-lm(市場報酬~return,data1) residual <- as.data.frame(fm$residual)
lm_final <- cbind(data1,residual)
colnames(lm_final) <- c("週期", "股票編號","市場報酬率","平均報酬率","殘差")