Bootstrapping with glm model - r

I have a negative binomial regression model where I predict Twitter messages' retweet count based on their use of certain word types (ME words, Moral words, and Emotional words):
M1 <- glm.nb(retweetCount ~ ME_words + Moral_words + Emo_words, data = Tweets)
I now want to sample with bootstrapping (for instance, samples of 1,000 with replacement from the dataframe's original 500,000 messages) from the large dataset, Tweets, to run iterations of the model and analyse the variance of the coefficients. What is the best approach to doing this? I am assuming I need to use the boot package, but I am a bit lost with where to start.
Ideally, I would like to create a for loop that can run a number of iterations, and then store the coefficients of each model iteration in a new dataframe. This would be extremely useful for future analyses.
Here is some reproducible data from the much much large dataframe Tweets:
>dput((head(Tweets, 100)))
structure(list(retweetCount = c(1388, 762, 748, 436, 342, 320,
312, 295, 264, 251, 196, 190, 175, 167, 165, 163, 149, 148, 148,
146, 133, 132, 126, 124, 122, 122, 121, 120, 118, 118, 114, 113,
112, 110, 108, 107, 104, 101, 100, 96, 95, 94, 93, 92, 90, 90,
89, 89, 87, 86, 84, 83, 83, 83, 82, 82, 82, 82, 78, 78, 78, 76,
76, 76, 76, 74, 74, 73, 73, 72, 72, 71, 70, 70, 70, 70, 69, 69,
69, 68, 68, 67, 65, 65, 65, 65, 63, 62, 62, 61, 61, 61, 61, 60,
60, 59, 59, 59, 59, 58), ME_words = c(2, 2, 2, 0, 0, 1, 1, 0,
1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1,
0, 3, 0, 1, 0, 1, 1, 4, 1, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0,
0, 0, 2, 2, 0, 0, 1, 0, 1, 0, 0, 2, 0, 0, 0, 1, 0, 1, 1, 0, 0,
0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 1, 0, 0, 0, 1, 0, 0), Moral_words = c(0, 0, 1, 1, 1, 2, 0,
0, 0, 1, 0, 1, 2, 0, 1, 1, 1, 2, 0, 1, 0, 1, 1, 0, 2, 0, 1, 1,
1, 0, 1, 1, 1, 1, 0, 2, 0, 1, 1, 1, 2, 0, 1, 1, 1, 1, 0, 1, 0,
0, 5, 1, 1, 1, 1, 2, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0, 2, 0, 0, 0,
1, 1, 2, 0, 0, 0, 0, 0, 1, 3, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1,
1, 1, 0, 0, 2, 2, 1, 0, 0), Emo_words = c(0, 0, 1, 1, 0, 0, 2,
0, 1, 0, 2, 0, 1, 0, 1, 2, 0, 3, 1, 1, 2, 0, 0, 0, 0, 0, 1, 1,
1, 2, 0, 1, 0, 0, 0, 1, 0, 1, 0, 2, 0, 0, 1, 0, 1, 1, 2, 0, 0,
1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 3, 0, 0, 2, 0, 0, 1, 0,
1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 2, 2, 1, 0, 0, 0, 0, 2, 1, 0, 0,
1, 0, 0, 1, 2, 2, 0, 0, 0)), row.names = c(NA, -100L), class = c("tbl_df",
"tbl", "data.frame"))

You can use the boot package, but for simple versions of the bootstrap it's almost simpler to roll your own.
fit initial model
library(MASS)
M1 <- glm.nb(retweetCount ~ ME_words + Moral_words +
Emo_words, data = Tweets)
set up data structure for results
nboot <- 1000
bres <- matrix(NA,nrow=nboot,
ncol=length(coef(M1)),
dimnames=list(rep=seq(nboot),
coef=names(coef(M1))))
bootstrap
set.seed(101)
bootsize <- 200
for (i in seq(nboot)) {
bdat <- Tweets[sample(nrow(Tweets),size=bootsize,replace=TRUE),]
bfit <- update(M1, data=bdat) ## refit with new data
bres[i,] <- coef(bfit)
}
structure output
data.frame(mean_est=colMeans(bres),
t(apply(bres,2,quantile,c(0.025,0.975))))

Related

How to prevent two NPCs from damaging each other with their AoE spells in Azerothcore?

I am running a local server of Azerothcore with rev. 3716ddf3e4e1 2021-05-25 18:05:13 +0200 (master branch).
I have created two custom NPCs and added them to my DB with the following code:
INSERT INTO `creature_template` (`entry`, `difficulty_entry_1`, `difficulty_entry_2`, `difficulty_entry_3`, `KillCredit1`, `KillCredit2`, `modelid1`, `modelid2`, `modelid3`, `modelid4`, `name`, `subname`, `gossip_menu_id`, `minlevel`, `maxlevel`, `exp`, `faction`, `npcflag`, `speed_walk`, `speed_run`, `scale`, `rank`, `dmgschool`, `DamageModifier`, `BaseAttackTime`, `RangeAttackTime`, `BaseVariance`, `RangeVariance`, `unit_class`, `unit_flags`, `unit_flags2`, `dynamicflags`, `family`, `trainer_type`, `trainer_spell`, `trainer_class`, `trainer_race`, `type`, `type_flags`, `lootid`, `pickpocketloot`, `skinloot`, `PetSpellDataId`, `VehicleId`, `mingold`, `maxgold`, `AIName`, `MovementType`, `InhabitType`, `HoverHeight`, `HealthModifier`, `ManaModifier`, `ArmorModifier`, `RacialLeader`, `movementId`, `RegenHealth`, `mechanic_immune_mask`, `spell_school_immune_mask`, `flags_extra`, `ScriptName`, `VerifiedBuild`) VALUES
(1112001, 0, 0, 0, 0, 0, 3456, 0, 0, 0, 'Mob1', '', 0, 43, 43, 0, 63, 0, 1, 1.14286, 3, 3, 0, 30, 2000, 2000, 1, 1, 1, 32832, 2048, 0, 0, 0, 0, 0, 0, 7, 4, 0, 0, 0, 0, 0, 50000, 60000, 'SmartAI', 1, 3, 1, 100, 1, 1, 0, 0, 1, 0, 0, 256, '', 12340),
(1112003, 0, 0, 0, 0, 0, 21443, 0, 0, 0, 'Mob2', '', 0, 42, 42, 0, 63, 0, 1, 1.14286, 1, 1, 0, 10, 2000, 2000, 1, 1, 1, 0, 2048, 0, 0, 0, 0, 0, 0, 6, 0, 4860, 0, 0, 0, 0, 297, 393, 'SmartAI', 1, 3, 1, 60, 1, 1, 0, 0, 1, 650854271, 0, 0, '', 12340);
Once i let Mob1 cast spell Death and Decay, Mob2 will take damage from it once they walk across it. How can i prevent the mobs from damaging each other, but only do damage to players instead?
Have you tried to set the two NPC to an allied faction that is also an enemy faction for the player ?

I have problem for calculate IDI and NRI with R

I'm trying to calculate the integrated discrimination improvement for two Cox regression models (time, event), using the survIDINRI package and the IDI.INF function and I have an error
This is the code for the function:
D=subset(donnees,select=c("time","status","age","smoking","hospit_HF","symptomatic_angina","cardiac2","nb_seg_LGE","ischemie"))
D$status=as.numeric(D$status==1 | D$status==2)
D=D[!is.na(apply(D,1,mean)),] ; dim(D)
mydata=D
indata2=mydata;
indata1=mydata[,-8];
indata0=mydata[,c(-7,-8)];n=nrow(D);
covs2<-as.matrix(indata2[,c(-1,-2)]);
covs1<-as.matrix(indata1[,c(-1,-2)]);
covs0<-as.matrix(indata0[,c(-1,-2)]);
t0=2
x<- IDI.INF(mydata[,1:2], covs0, covs1, t0) ;
And I get the following error message:
Error in unoecdf(cc, pdiff[case], Wi[case] * PTB.Vi[case]) :
NA/NaN/Inf in foreign function call (arg 5)
If someone have a solution it's would be great
Thanks in advance
Marilyn
> dput(round(mydata[1:700,],1))
structure(list(time = c(6.8, 6.8, 6.9, 7.8, 5.6, 6.7, 8.3, 6.6,
7.8, 3.7, 6.9, 6.5, 7, 3.4, 7.4, 6.8, 6.8, 6.9, 7.8, 0.2, 7,
5.2, 6.9, 6.4, 6.5, 6.9, 6.7, 6.9, 6.9, 3.5, 0.7, 1.9, 7.3, 6.9,
7.4, 6.9, 2, 3.1, 6.8, 8, 8.1, 6.8, 6.9, 6.9, 6.8, 0.2, 7.9,
6.9, 5.2, 8.1, 6.7, 6.8, 7.8, 8.1, 7, 6.7, 1.2, 7.8, 7.8, 6.7,
6.6, 6.9, 6.9, 6.4, 7.2, 2.1, 5.2, 7.5, 7.8, 1.1, 0.8, 1.9, 6.9,
6.9, 7.1, 6.5, 7.7, 6.9, 7.4, 6.9, 7.1, 3.6, 7.9, 6.7, 6.9, 0.4,
6.9, 5.9, 6.7, 6.8, 7.9, 6.5, 8, 5.1, 6.9, 6.9, 8.2, 7, 5.2,
7, 4.3, 8.3, 6.8, 6.7, 6.8, 6.8, 7.2, 1.5, 7.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, 82, 68, 75,
72, 74, 73, 83, 85, 69, 64, 72, 82, 73, 79, 57, 78, 63, 72, 84,
76, 74, 77, 85, 77, 59, 71, 74, 80, 84, 70, 74, 77, 82, 58, 79,
77, 83, 69, 81, 75, 65, 65, 54, 80, 73, 64, 69, 78, 62, 77, 47,
65, 58, 79, 83, 72, 69, 77, 79, 79, 75, 71, 82, 70, 83, 82, 86,
77, 51, 85, 61, 77, 63, 78, 64, 59, 71, 79, 86, 75, 77, 78, 69,
75, 67, 68, 72, 68, 52, 81, 70, 82, 68, 80, 86, 72, 70, 78, 68,
65, 69, 67, 88, 77, 67, 83, 76, 85, 79, 59, 58, 79, 79, 74, 80,
79, 71, 75, 78, 72, 61, 89, 64, 79, 54, 59, 56, 67, 59, 70, 71,
69, 64, 63, 62, 83, 80, 72, 78, 91, 78, 46, 84, 72, 68, 80, 80,
88, 77, 63, 68, 85, 56, 57, 71, 84, 84, 79, 76, 74, 74, 74, 60,
73, 79, 76, 86, 82, 79, 58, 58, 78, 73, 73, 73, 82, 70, 60, 54,
64, 77, 66, 64, 59, 74, 62, 78, 76, 85, 63, 78, 73, 81, 79, 91,
89, 56, 56, 71, 87, 88, 65, 65, 67, 69, 67, 60, 72, 81, 64, 73,
77, 65, 74, 52, 74, 72, 72, 83, 61, 51, 86, 69, 69, 69, 84, 75,
83, 77, 70, 78, 65, 79, 85, 70, 73, 63, 80, 74, 82, 43, 88, 74,
73, 77, 60, 72, 66, 73, 70, 86, 66, 79, 65, 48, 68, 56, 72, 72,
81, 82, 85, 76, 81, 64, 66, 64, 62, 44, 68, 80, 87, 59, 81, 85,
61, 83, 58, 71, 81, 86, 83, 55, 59, 66, 72, 82, 75, 64, 68, 42,
61, 76, 76, 63, 77, 76, 78, 70, 71, 79, 78, 61, 80, 64, 80, 80,
69, 65, 78, 79, 68, 85, 78, 87, 74, 80, 79, 81, 80, 81, 65, 72,
78, 82, 66, 75, 86, 41, 41, 58, 77, 59, 71, 51, 70, 48, 46, 63,
76, 88, 76, 76, 61, 44, 71, 79, 63, 67, 71, 77, 69, 84, 85, 79,
79, 70, 82, 73, 79, 51, 72, 72, 75, 72, 70, 76, 82, 73, 80, 80,
70, 68, 71, 57, 78, 82, 74, 80, 62, 80, 70, 55, 70, 76, 84, 76,
63, 60, 78, 72, 78, 76, 80, 62, 65, 68, 85, 71, 75, 78, 69, 63,
69, 60, 82, 80, 69, 64, 76, 52, 76, 58, 54, 79, 65, 76, 75, 74,
65, 81, 89, 52, 81, 89, 67, 72, 62, 53, 51, 67, 77, 52, 64, 62,
82, 76, 64, 80, 63, 78, 59, 73, 69, 68, 52, 76, 61, 62, 58, 69,
78, 86, 82, 70, 70, 75, 78, 72, 67, 54, 74, 82, 51, 69, 75, 70,
78, 73, 77, 64, 72, 82, 46, 65, 70, 68, 81, 67, 81, 76, 49, 60,
70, 68, 66, 75, 74, 70, 62, 62, 72, 43, 68, 55, 74, 65, 82, 77,
78, 61, 76, 66, 66, 75, 67, 60, 68, 72, 76, 69, 82, 69, 67, 80,
55, 79, 76, 76, 67, 66, 66, 81, 68, 75, 75, 71, 70, 57, 75, 74,
64, 71, 66, 68, 66, 92, 76, 64, 76, 55, 63, 57, 70, 79, 71, 77,
69, 62, 57, 67, 65, 56, 74, 76, 58, 78, 71, 52, 65, 75, 79, 57,
70, 66, 70, 72, 63, 64, 54, 46, 79, 63, 70, 83, 75, 57, 70, 75,
69, 65, 81, 46, 68, 65, 65, 63, 74, 75, 81, 64, 82, 61, 65, 69,
69, 83, 68, 72, 74, 79, 69, 83, 82, 85, 62, 73, 63, 75, 81, 62,
68, 85, 66, 78, 78, 68, 75, 78, 81, 68, 69, 68, 52, 83, 82, 57,
77, 55, 83, 74, 74, 64, 74, 58, 47, 74, 72, 71, 56, 66, 84, 67,
59, 69, 46, 58, 71, 76, 50, 56), smoking = c(0, 0, 0, 0, 0, 0,
1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0,
0, 0, 0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0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1,
0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0,
0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0,
0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1)), row.names = c(NA,
-700L), class = c("tbl_df", "tbl", "data.frame"))

The output from LPSolver is not the optimal result

Since I need to create an automatic shift planning tool, R lpSolve is the package I plan to use. However, I can't get the optimal output by the code shown as below. The output(hourly supply by accumulating all shifts available) can't fulfill the demand. e.g. The demand for a hour is 46 but the supply is only 25 which means 21 unit of demand can't be satisfied.
Background:
The objective
To minimize the difference between total supply and total demand.
To minimize the difference between supply and demand for each hour.
Constraint
Shift constraint - each hour might have several shifts available to be assigned.
Max capacity - I have the cap of supply. the sum of total shift cant exceed the cap for each hour. (46 is the cap in this example).
In the constr matrix, 24 rows represent 24 hours starting from 7 am and 9 columns refers to no. of shifts I have.
The constr.val refers to hourly demand.
Please let me know if there is anything unclear. thanks!
library(lpSolve)
obj.fun<-c(1,1,1,1,1,1,1,1,1)
constr<-matrix(c(
1, 0, 0, 0, 0, 0, 0, 0, 0,
1, 0, 0, 0, 0, 0, 0, 0, 0,
1, 0, 0, 0, 0, 0, 0, 0, 0,
1, 0, 0, 1, 0, 0, 0, 0, 0,
1, 0, 0, 1, 0, 1, 0, 0, 0,
1, 0, 0, 1, 0, 1, 0, 1, 0,
1, 0, 0, 1, 0, 1, 0, 1, 0,
1, 0, 0, 1, 0, 1, 0, 1, 0,
0, 1, 0, 1, 0, 1, 0, 1, 0,
0, 1, 0, 1, 0, 1, 0, 1, 0,
0, 1, 0, 1, 0, 1, 0, 1, 0,
0, 1, 0, 0, 1, 1, 0, 1, 0,
0, 1, 0, 0, 1, 0, 1, 1, 0,
0, 1, 0, 0, 1, 0, 1, 0, 1,
0, 1, 0, 0, 1, 0, 1, 0, 1,
0, 1, 0, 0, 1, 0, 1, 0, 1,
0, 0, 1, 0, 1, 0, 1, 0, 1,
0, 0, 1, 0, 1, 0, 1, 0, 1,
0, 0, 1, 0, 1, 0, 1, 0, 1,
0, 0, 1, 0, 0, 0, 1, 0, 1,
0, 0, 1, 0, 0, 0, 0, 0, 1,
0, 0, 1, 0, 0, 0, 0, 0, 0,
0, 0, 1, 0, 0, 0, 0, 0, 0,
0, 0, 1, 0, 0, 0, 0, 0, 0), nrow = 24, byrow = TRUE)
constr.dir <- rep("<=", 24)
constr.val <- c(24, 20, 21, 22, 26, 34, 40, 44,
46, 46, 46, 46, 46, 46, 46, 46,
46, 46, 46, 46, 46, 46, 41, 27)
day.shift <- lp("max", obj.fun, constr, constr.dir,
constr.val, compute.sens = TRUE)
day.shift$solution

Error in WinBUGS CODE

I could not get the WinBUGS code below to work. It works for normal priors, but not for uniform priors. The error message that appears after I click compile is array index is greater than array upper bound for age. What does that mean? Can any one please help me work the code below please?
model
{
for (i in 1:n) {
# Linear regression on logit
logit(p[i]) <- alpha + b.sex*sex[i] + b.age*age[i]
# Likelihood function for each data point
frac[i] ~ dbern(p[i])
}
alpha ~ dunif(0, 1) # Prior for intercept
b.sex ~ dunif(0, 1) # Prior for slope of sex
b.age ~ dunif(0, 1) # Prior for slope of age
}
Data
list(sex=c(1, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1,
1, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0,
0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1,
0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1),
age= c(69, 57, 61, 60, 69, 74, 63, 68, 64, 53, 60, 58, 79, 56, 53, 74, 56, 76, 72,
56, 66, 52, 77, 70, 69, 76, 72, 53, 69, 59, 73, 77, 55, 77, 68, 62, 56, 68, 70, 60,
57, 51, 51, 63, 57, 80, 52, 65, 72, 80, 73, 76, 79, 66, 51, 76, 75, 66, 75, 78, 70,
67, 51, 70, 71, 71, 74, 74, 60, 58, 55, 61, 65, 52, 68, 75, 52, 53, 70),
frac=c(1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0,
1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1,
1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1,
1, 0, 1, 1, 0, 0, 1, 0, 0, 1),
n=100)
Initial Values
list(alpha=0.5, b.sex=0.5, b.age=0.5)
Oh, that's clear. WinBUGS says array index is greater than array upper bound for age.
That clearly hints an error -> I see you have n = 100 and the age list is not long enough:
> your_list <- list(...)
> str(your_list)
List of 4
$ sex : num [1:100] 1 1 1 0 1 1 0 0 0 0 ...
$ age : num [1:79] 69 57 61 60 69 74 63 68 64 53 ...
$ frac: num [1:100] 1 1 1 0 1 1 0 1 1 0 ...
$ n : num 100
Anyways, I wouldn't use uniform prior here; unless you actually know what you are doing, I would recommend flat normal, like dnorm(0, 1.0E-10) or so. You should also allow negative values for the coefficients. The "null hypothesis" normally is that the coefficient is zero, so for the mean value of the posterior distribution of the coefficient to be zero, you should "allow it some space from both sides" (intuitivelly said).

image function in R

I'm trying to do something a little bit complicated for a beginner in programming.
I have a matrix 16x16 and I want to plot the values as a heatmap using image() in R.
How can I plot the "0" (zeros) in blue when the sum (row index + column index) is <= 15? Is that possible?
example matrix:
x <- c(3045, 893, 692, 830, 617, 155, 246, 657, 105, 60, 18, 7, 7, 4, 2, 11234,
2985, 2242, 2471, 1575, 366, 503, 1283, 170, 79, 32, 6, 4, 1, 3, 19475, 4756,
3233, 3251, 1810, 409, 575, 1210, 139, 41, 11, 4, 2, 0, 0, 20830, 4739, 2990,
2531, 1346, 298, 325, 612, 60, 17, 1, 0, 1, 0, 0, 15304, 3196, 1885, 1440, 610,
117, 115, 185, 14, 2, 0, 0, 0, 0, 0, 8026, 1535, 806, 539, 223, 33, 37, 39, 0,
0, 0, 0, 0, 0, 0, 3300, 562, 286, 141, 45, 14, 5, 12, 0, 0, 0, 0, 0, 0, 0, 1067,
160, 65, 40, 14, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 277, 47, 6, 2, 1, 0, 1, 0, 0, 0,
0, 0, 0, 0, 0, 72, 6, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 5, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
xmat <- matrix(x, ncol = 12)
xmat <- cbind(xmat, rep(0,16), rep(0,16), rep(0,16), rep(0,16))
xmat <- rbind(xmat, rep(0,16))
dimnames(xmat) = list(0:15, 0:15)
xmat
Thanks!
Vitor
Plot the cases meeting the criteria as blue.
xmat.new <- xmat
xmat.new[!((row(xmat) + col(xmat) <= 15) & xmat==0)] <- NA
image(xmat.new,col="blue")
Plot the cases not meeting the criteria as normal. Notice the add=TRUE
xmat.new <- xmat
xmat.new[((row(xmat) + col(xmat) <= 15) & xmat==0)] <- NA
image(xmat.new,add=TRUE)
Result:
Edited to include #Marek's suggestion to simplify the statements.

Resources