Linear model: Least-Squares Fit

This commit is contained in:
Noah L. Schrick 2022-04-11 13:37:21 -05:00
parent 952c77d802
commit f02246966c

View File

@ -1,4 +1,28 @@
# Homework 4 for the University of Tulsa' s CS-7863 Network Theory Course # Homework 4 for the University of Tulsa' s CS-7863 Network Theory Course
# Degree Distribution # Degree Distribution
# Professor: Dr. McKinney, Spring 2022 # Professor: Dr. McKinney, Spring 2022
# Noah Schrick - 1492657 # Noah Schrick - 1492657
library(igraph)
library(igraphdata)
data(yeast)
g <- yeast
################# Linear model: Least-Squares Fit #################
g.hist <- hist(degree(g), freq=FALSE)
g.seq <- 0:max(degree(g)) # x-axis
g.breaks <- g.hist$breaks[-c(1,2)] # remove 0 and low degrees
g.probs <- g.hist$density[-1] # make lengths match
# Need to clean up probabilities that are 0
nz.probs.mask <- g.probs!=0
g.breaks.clean <- g.breaks[nz.probs.mask]
g.probs.clean <- g.breaks[nz.probs.mask]
plot(log(g.breaks.clean), log(g.probs.clean))
g.fit <- lm(log(g.probs.clean)~log(g.breaks.clean))
summary(g.fit)
coef(g.fit)[2]
################# Max-Log-Likelihood #################