I have data from these set of experiments:
In each experiment I infect a neuron with a rabies virus. The virus climbs backwards across the dendrites of the infected neuron and jumps across the synapse to the input axons of that neuron. In the input neurons the rabies will then express a marker gene thereby labeling them. This allows me to see which neurons are inputs to the target neuron I infected and thus create a connectivity map of a certain region in the brain.
In each experiment I obtain counts of all the infected input neurons of the target neuron I infected.
Here's a simulation of the data: (3 targets and 5 inputs)
set.seed(1) probs <- list(c(0.4,0.1,0.1,0.2,0.2),c(0.1,0.3,0.4,0.1,0.1),c(0.1,0.1,0.4,0.2,0.2)) mat <- matrix(unlist(lapply(probs,function(p) rmultinom(1, as.integer(runif(1,50,150)), p))),ncol=3) inputs <- LETTERS[1:5] targets <- letters[1:3] df <- data.frame(input = c(unlist(apply(mat,2,function(x) rep(inputs ,x)))),target = rep(targets ,apply(mat,2,sum)))
What I'd like to estimate is the effect of each target neuron on these counts, relative to the grand mean. I was thinking that a multinomial regression model is appropriate in this case, where the contrasts are set to the
library(foreign) library(nnet) library(reshape2) df$input <- factor(df$input,levels=inputs) df$target <- factor(df$target,levels=targets) fit <- multinom(input ~ target, data = df,contrasts = list(target = "contr.sum")) # weights: 20 (12 variable) initial value 505.363505 iter 10 value 445.057386 final value 441.645283 converged
Which gives me:
> summary(fit)$coefficients (Intercept) target1 target2 B 0.08556288 -1.743854 1.6062660 C 0.55375003 -2.094266 1.2616939 D -0.17624590 -1.364270 0.6284231 E -0.04091248 -1.617374 0.6601274
So the effects for
input A are not reported and I would like to obtain both the effects of all
targets on all
I'm wondering if adding a mean across
targets and a mean across
inputs, and setting them as baseline
dummy variables is a good solution:
#add target mean mat <- cbind(mat,round(apply(mat,1,mean))) colnames(mat)[ncol(mat)] <- "x" targets <- c(targets,"x") #add input mean mat <- rbind(mat,round(apply(mat,2,mean))) rownames(mat)[nrow(mat)] <- "X" inputs <- c(inputs,"X")
X represent the means of
inputs, respectively, and are rounded so that they are counts.
df <- data.frame(input = c(unlist(apply(mat,2,function(x) rep(inputs ,x)))),target = rep(targets ,apply(mat,2,sum))) df$input <- factor(df$input,levels=rev(inputs)) df$target <- factor(df$target,levels=rev(targets))
And then fit the
multinom regression using
fit <- multinom(input ~ target, data = df)