我有完整的这段代码,并且我已经导入了ggplot2软件包:
library(fitdistrplus)
library(MASS)
library(survival)
library(tidyverse)
library(ggplot2)
library(actuar)
library(e1071)
library(FAdist)
library(gld)
library(MonteCarlo)
library(snow)
lista_df <- lapply(archivos, function (x) read.table(x, sep=";",header=T))
df_unido <- reduce(rbind, lista_df)
df_unido_n <- df_unido %>%
dplyr::select(NombreCentral,POTENCIA_BRUTA_MWH,CONCENTRACION_PORCENTAJE_CO2) %>%
filter(POTENCIA_BRUTA_MWH >0,!is.na(POTENCIA_BRUTA_MWH) , CONCENTRACION_PORCENTAJE_CO2 >0, !is.na(CONCENTRACION_PORCENTAJE_CO2))
nombres= df_unido_n$NombreCentral
nombres.factor=factor(nombres)
nmb=levels(nombres.factor)
lista_total= list()
for (i in 1:44){
dfn=df_unido_n %>%
filter(NombreCentral == nmb[i])
lista_total[[i]]<-dfn
}
但是,当您到达此处时,想要执行以下几行,就像阅读它们但不关心它们,然后尝试重新启动Rstudio,什么也没做。
ggplot(lista_total[[24]], aes(x = CONCENTRACION_PORCENTAJE_CO2)) + geom_density()
ggplot(lista_total[[24]], aes(lista_total[[24]]$CONCENTRACION_PORCENTAJE_CO2)) + geom_histogram(binwidth = 1.2)
ggplot(lista_total[[24]], aes(lista_total[[24]]$CONCENTRACION_PORCENTAJE_CO2)) + stat_ecdf(geom = "point", size=1) + ggtitle("CDF GRAPHIC")
ggplot(lista_total[[24]], aes(x = CONCENTRACION_PORCENTAJE_CO2)) + geom_histogram(aes(y=..density..), binwidth=1, colour="black", fill="white") + geom_density(alpha=0.2, size=0.4) + ggtitle("DENSITY AND HISTOGRAM GRAPHIC")
quan <- quantile(lista_total[[24]]$CONCENTRACION_PORCENTAJE_CO2, probs = c(0.25, 0.5, 0.75, 1))
我还尝试删除几乎整个环境,并将所有变量1加载到1,这是第一次成功,但此后再也没有了。
col_prueba=lista_total[[24]]$CONCENTRACION_PORCENTAJE_CO2
col_prueba_aux=(lista_total[[24]]$CONCENTRACION_PORCENTAJE_CO2)/10^4
str(col_prueba)
summary(col_prueba)
plotdist(col_prueba, histo=TRUE, demp=TRUE)
descdist(col_prueba)
fw2_p <- fitdist(col_prueba, "weibull")
fw3_p <- fitdist(col_prueba, "weibull3", start = list(shape = 1, scale = 1))
fg_p <- fitdist(col_prueba, "gamma")
fln_p <- fitdist(col_prueba, "lnorm")
fex_p <- fitdist(col_prueba, "exp")
fgm_p <- fitdist(col_prueba, "gumbel", start=list(scale=50, location=50))
fn_p <- fitdist(col_prueba, "norm")
fll_p <- fitdist(col_prueba, "llogis", start = list(shape = 1, scale = 1))
fl_p <- fitdist(col_prueba, "logis")
fitGLD <- fit.fkml(col_prueba, method = "ML")
optGLD <- fitGLD$optim.results$par
opt <- round(optGLD ,1)
fgl_p<- fitdist(col_prueba, "gl", start=list(lambda1 = opt[1], lambda2 = opt[2], lambda3 = opt[3], lambda4 = opt[4]), method="mle", control=list(trace=0, REPORT=1))
par(mfrow=c(2,2))
plot.legend<-c("Weibull","Weibull3","lnorm","gamma","exp","gumbel","norm","llogis","logis","g-lambda")
这里也发生同样的事情:
denscomp(list(fw2_p,fw3_p,fg_p,fln_p,fex_p,fgm_p,fn_p,fll_p,fl_p,fgl_p), plotstyle = "ggplot",legendtext = c("weibull-2P", "weibull-3P", "gamma", "lognormal", "exponential", "gumbel", "normal", "loglogistic", "logistic","g-lambda"))
cdfcomp(list(fw2_p,fw3_p,fg_p,fln_p,fex_p,fgm_p,fn_p,fll_p,fl_p,fgl_p), plotstyle = "ggplot",legendtext = c("weibull-2P", "weibull-3P", "gamma", "lognormal", "exponential", "gumbel", "normal", "loglogistic", "logistic","g-lambda"))
qqcomp(list(fw2_p,fw3_p,fg_p,fln_p,fex_p,fgm_p,fn_p,fll_p,fl_p,fgl_p), plotstyle = "ggplot",legendtext = c("weibull-2P", "weibull-3P", "gamma", "lognormal", "exponential", "gumbel", "normal", "loglogistic", "logistic","g-lambda"))
ppcomp(list(fw2_p,fw3_p,fg_p,fln_p,fex_p,fgm_p,fn_p,fll_p,fl_p,fgl_p), plotstyle = "ggplot",legendtext = c("weibull-2P", "weibull-3P", "gamma", "lognormal", "exponential", "gumbel", "normal", "loglogistic", "logistic","g-lambda"))
test_func<-function(n,loc,scale){
sample<-rnorm(n, loc, scale)
stat<-sqrt(n)*mean(sample)/sd(sample)
decision<-abs(stat)>1.96
return(list("decision"=decision, "stat"=stat))
}
n_grid<-c(50,100,250,500)
loc_grid<-c(0,1)
scale_grid<-c(1,2)
param_list=list("n"=n_grid, "loc"=loc_grid, "scale"=scale_grid)
erg<-MonteCarlo(func=test_func, nrep=250, param_list=param_list, ncpus=1)
df<-MakeFrame(erg)
head(df)
我已经在另一个工作选项卡中完成了此功能,但是我什么都没画
tbl <- tbl_df(df)
ggplot(filter(tbl, loc==0)) + geom_density(aes(x=stat, col=factor(n)))
作为一个细节,这段代码的功能越来越慢,在每个过程中花费的时间越来越长,所以我不知道它是我的计算机,代码还是两者的混合体。请帮助大家!!!