Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
错误:意外';}';在:";}&引用;R中的非参数与OLS_R_Statistics - Fatal编程技术网

错误:意外';}';在:";}&引用;R中的非参数与OLS

错误:意外';}';在:";}&引用;R中的非参数与OLS,r,statistics,R,Statistics,我对R(用于使用STATA)相当陌生,似乎有一个错误:“}”中出现意外的“}”。我似乎找不到问题所在。我将非参数方法与混合OLS进行比较,看看哪种方法在不久前公布的公共数据集中表现更好。我知道我已经分配了一个小环路和一个小n列。任何帮助都会很好。非常感谢 M <- 10 n.train <-90 n <- nrow(smokedatasample) write(c("linear","ll"),file="psedata.xlsx",ncol=2) train <-

我对R(用于使用STATA)相当陌生,似乎有一个错误:“}”中出现意外的“}”。我似乎找不到问题所在。我将非参数方法与混合OLS进行比较,看看哪种方法在不久前公布的公共数据集中表现更好。我知道我已经分配了一个小环路和一个小n列。任何帮助都会很好。非常感谢

M <- 10
n.train <-90
n <- nrow(smokedatasample)

write(c("linear","ll"),file="psedata.xlsx",ncol=2)

train <- smokedatasample

sample.OLS <- lm(model.formula.birth,data=smokedatasample, x=TRUE,y=TRUE)
np.smoke.reg <- npreg(np.formula,data=smokedatasample,regtype="ll",nmulti=1)

pse.lm <- numeric()
pse.ll <- numeric()

for(m in 1:M) {

smoke.shuffle <- smokedatasample[sample(1:n,replace=FALSE),]

train <- smoke.shuffle[1:n.train,]
eval <- smoke.shuffle[(n.train+1):n,]

shuffle.sample.OLS <- lm(model.formula.birth, data=train)

yhat.OLS <- predict(shuffle.sample.OLS, newdata=eval)

pse.lm[m] <- mean((eval$dbirwt-yhat.OLS)^2)

shuffle.np.smoke.reg <- npreg(np.formula,data=train, regtype=np.smoke.reg$bws$regtype, 
                              ckertype=np.smoke.reg$bws$ckertype, 
                              ckerorder=np.smoke.reg$bws$ckerorder, 
                              ukertype=np.smoke.reg$bws$ukertype, 
                              okertype=np.smoke.reg$bws$okertype, 
                              bws=np.smoke.reg$bws$bw)

yhat.np <- predict(shuffle.np.smoke.reg, newdata=eval)

pse.ll[m] <- mean((eval$dbirwt-yhat.np)^2)

write(c(pse.lm[m],pse.ll[m], file= "psedata.xlsx" , ncol=2 ,append=TRUE)

}

M您在
}
之前的最后一行忘记了一个括号

write(c(pse.lm[m],pse.ll[m]), file= "psedata.xlsx" , ncol=2 ,append=TRUE)
而不是

write(c(pse.lm[m],pse.ll[m], file= "psedata.xlsx" , ncol=2 ,append=TRUE)

上一个命令中缺少括号。应该是
c(pse.lm[m],pse.ll[m])
我建议使用一个IDE来帮助您找到匹配的括号。谢谢您的建议非常感谢,它一定很晚了;)