Skip to content

Instantly share code, notes, and snippets.

@SirmaXX
Last active December 2, 2023 13:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SirmaXX/4d216ef4c937a0e8bfea38de14a1a8f7 to your computer and use it in GitHub Desktop.
Save SirmaXX/4d216ef4c937a0e8bfea38de14a1a8f7 to your computer and use it in GitHub Desktop.
alıştırma için örnek simülasyon,n sayısı değişken
library(ggplot2)
library(dplyr)
set.seed(100)
#örneklem sayısı tanımlayınız.
n<-50
x_values <- round(runif(n, min = -1, max = 1), 4)
########### ########### olasılık yoğunluk fonksiyonu ###########
expdf <- function(xvalue) {
stopifnot(all(xvalue >= -1), all(xvalue <= 1))
pdf_values <- ifelse(xvalue >= -1 | xvalue <= 1, 1/2 * (1 - xvalue^2), 0)
return(pdf_values)
}
# Print the generated values
print(x_values)
pdf_values <- expdf(x_values)
df1 <- data.frame(
x_values = x_values,
pdf = c(pdf_values),
beta = rep(c("beta=0"), each = length(x_values))
)
# Plot with ggplot2
ggplot(df1, aes(x_values, color = beta, linetype = beta, group = beta)) +
geom_density(size = 0.5) +
labs(title = "olasılık yoğunluk fonksiyonun grafiği", x = "x", y = "f(x)") +
theme_minimal() +
scale_color_manual(values = c( "red")) +
scale_linetype_manual(values = c(1, 1, 1, 1, 1, 1, 1)) +
theme(legend.position = "topright")
########### ########### kümülatif dağılım fonksiyonu ###########
excdf <- function(xvalue) {
stopifnot(all(xvalue >= -1), all(xvalue <= 1))
cdf_values <- ifelse( xvalue >= -1 | xvalue <= 1, 1/2 *(xvalue- (xvalue^3/3)+4/3) , 0)
return( cdf_values )
}
cdf_values <- excdf(x_values)
df <- data.frame(
x_values = x_values,
cdf = cdf_values,
beta = rep(c("beta=0"), each = length(x_values))
)
ggplot(df, aes(x_values, cdf, color = beta, linetype = beta)) +
geom_line(size = 0.5) +
labs(title = "kümülatif dağılım fonksiyonu", x = "x", y = "F(x)") +
theme_minimal() +
scale_color_manual(values = c("blue")) +
scale_linetype_manual(values = c(1, 1, 1, 1, 1, 1, 1)) +
theme(legend.position = "topright")
########### ORTALAMALARIN DAĞILIMI ###########
meandist <- list() #
i <- 1
while (i < n) {
# Generate 50 random float values between -1 and 1
x_values1 <- round(runif(n, min = -1, max = 1), 4)
pdf_values <- excdf(x_values1)
# Print the mean and append it to meandist
mean_val <- mean(pdf_values)
print(mean_val)
meandist[[i]] <- mean_val
# Print the current iteration
print(i)
i <- i + 1
}
# Assuming 'meandist' is a list of numeric values
meandist <- unlist(meandist)
# Create a histogram
hist_data <- hist(meandist, plot = FALSE)
# Convert histogram data to a data frame
df <- data.frame(value = hist_data$breaks[-length(hist_data$breaks)], count = hist_data$counts)
# Plot the frequency distribution
ggplot(data = df, aes(x = value, y = count)) +
geom_bar(stat = "identity", width = diff(hist_data$breaks)[1]) +
labs(x = "Value", y = "Frequency", title = "Frequency Distribution of Values in meandist")
shapiro.test(meandist)
#not shapiro wilk testinin olasılık değeri 0.05 den büyük ise normal dağılımdan türetildiğini söyleyebiliriz.
# 0.2917 çıkıyor
ks.test(meandist, 'pnorm')
# 3.331e-16 0.05 ten küçük olduğu için red ediyoruz
# not:shapiro wilk küçük örneklem sayıları için daha güçlüdür
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment