-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlab2-utils.R
63 lines (54 loc) · 1.8 KB
/
lab2-utils.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# Lab 5 Utilities
# Plot Grey's Anatomy networks
# Just a regular plot, but with men blue and women pink
# Assumes "sex" attribute
gaplot <- function(gr, names=TRUE)
{
nlist <- rep("", vcount(gr))
if (names)
{
nlist <- V(gr)$vertex.names
}
plot(gr, vertex.color=c("#8888FF","pink")[1+(V(gr)$sex=="F")],
vertex.label=nlist,
# vertex.label.size=.75,
vertex.size=15)
}
# invlogit (x)
# Computes the inverse logit function.
# Useful for turning log-odds into probability
invlogit <- function(x) {
exp(x) / (1 + exp(x))
}
# gof_trim
# Use this to avoid the error that occurs when plotting gof objects
# with a large number of parameters. The error is
# 'names' [y] attribute must be the same length as vector [x].
# Call with x as the second parameter to trim the number of parameters
# to what the plotting function expects.
# Input:
# gofm: A gofobject. Only tested on gof(g, GOF=~model) objects
# x: The desired length of the parameter vector. This can be determined
# from the error message.
# Output:
# A copy of the gofobject with the parameters trimmed.
# One could imagine a more elegant way to do this, via slices, boolean
# subsetting, etc.
gof_trim <- function(gofm, x) {
gofm2 <- gofm
# pval.model is a data frame dim y,5
gofm2$pval.model <- gofm$pval.model[1:x,]
# summary.model is a data frame dim y,5
gofm2$summary.model <- gofm$summary.model[1:x,]
# pobs.model is a named vector dim y
gofm2$pobs.model <- gofm$pobs.model[1:x]
# psim.model is a data frame dim k,y
gofm2$psim.model <- gofm$psim.model[,1:x]
# bds.model is a data frame dim 2,y
gofm2$bds.model <- gofm$bds.model[,1:x]
# obs.model is a named vector dim y
gofm2$obs.model <- gofm$obs.model[1:x]
# sim.model is a data frame dim k,y
gofm2$sim.model <- gofm$sim.model[,1:x]
return (gofm2)
}