I am trying to use R for the first time to do some probit analaysis.
I get the following error:
Error in if (!(validmu(mu) && valideta(eta))) stop("cannot find valid starting values: please specify some", :
missing value where TRUE/FALSE needed
This is the command I am using:
m1=glm(Good~Stg.Days+Dev.Deployments+Check.Ins+NoOfDevelopers,family=poisson(link = "probit"),data=deploy[1:4,])
My data deploy[1:4,] are as loaded in from a CSV file follows:
Good,Application Type,Project,Start Date,End Date,Stg Days,Dev Deployments,Check Ins,NoOfDevelopers
1,DocumentPlatform,ZCP,11/08/2010,11/11/2010,0.6,0,12,4
1,DocumentPlatform,ZCP,11/11/2010,09/12/2010,0.4,0,4,1
0,DocumentPlatform,ZCP,09/12/2010,07/03/2011,10,0,7,3
1,FactsheetPlatform,Process.ARCH,28/06/2010,09/03/2011,7.1,0,18,2
deploy is in reality a much bigger vector than 1:4 I am just using a subset of the data to help determine the problem.
Any ideas what is wrong?
As i commented: Using ?glm I found tha the poisoon family supports the following links: log, identity, and sqrt.
Testing on another link:
test <- data.frame('Good'=c(1,1,0,1),'Stg Days'=c(0.6,0.4,10,7.1),'Dev Deployments'=c(0,0,0,0),'Check Ins'=c(12,4,7,18),'NoOfDevelopers'=c(4,1,3,2))
m1=glm(Good~ . ,family=poisson(link = "log"),data=test)
Gives no errors. So I think your link = "probit" is the problem.
Related
I'm trying to access an API from iNaturalist to download some citizen science data. I'm using the package rinat to get this done (see vignette). The loop below is, essentially, pulling all observations for one species, in one state, in one year iteratively on a per-month basis, then summing the number of observations for that year (input parameters subset from my actual script for convenience).
require(rinat)
state_ids <- c(18, 14)
bird_ids <- c(14886,1409)
months <- c(1:12)
final_nums <- vector()
for(i in 1:length(state_ids)){
total_count <- vector()
for(j in 1:length(months)){
monthly <- get_inat_obs(place_id=state_ids[i],
taxon_id=bird_ids[i],
year=2019,
month = months[j])
total_count <- append(total, length(monthly$scientific_name))
print(paste("done with month", months[j], "in state", state_ids[i]))
}
final_nums <- append(final_nums, sum(total_count))
print(paste("done with state", state_ids[i]))
}
Occasionally, and seemingly randomly, I get the following error:
No encoding supplied: defaulting to UTF-8.
Error in if (!x$headers$`content-type` == "text/csv; charset=utf-8") { :
argument is of length zero
This ends up breaking the loop or makes the loop run without actually pulling any real data. Is this an issue with my script, or the API, or something else? I've tried manually supplying encoding information to the get_inat_obs() function, but it doesn't accept that as an argument. Thank you in advance!
I don't believe this is an error in your script. The issue is with the api most likely.
the error argument is of length zero is a common error when you try to make a comparison that has no length. For example:
if(logical(0) == "TEST") print("WORKED!!")
#Error in if (logical(0) == "TEST") print("WORKED!!") :
# argument is of length zero
I did some a few greps on their source code to see where this if statement is and it seems to be within inat_handle line 211 in get_inate_obs.R
This would suggest that the authors did not expect for
!x$headers$`content-type` == 'text/csv; charset=utf-8'
to evaluate to logical(0), but more specifically
x$headers$`content-type`
to be NULL.
I would suggest making a bug report on their GitHub and recommend they change the specified line to:
if(is.null(x$headers$`content-type`) || !x$headers$`content-type` == 'text/csv; charset=utf-8'){
Suggesting a bug is usually more well received if you have a reproducible example.
Also, you could totally make this change yourself locally by cloning out the git repository, editing the file, rebuild the package, and then confirm if you no longer get an error in your code.
I am trying to run an R loop on an individual based model. This includes two lists referring to grid cells, which I originally ran into difficulties with because they returned the error: Error: (list) object cannot be coerced to type 'double'. I think I have resolved this error by typing "as.numeric(unlist(x))."
Example from code:
List 1:
dredg<-list(c(943,944,945,946,947,948,949...1744,1745))
dredging<-as.numeric(unlist(dredg)). I refer to 'dredging' in my code, not 'dredg.'
List 2:
nodredg<-list(c(612,613,614,615,616,617,618,619,620,621,622,623,624,625,626,627,628,629,630,631))
dcells<-as.numeric(unlist(nodredg)) I refer to 'dcells' in my code, not 'nodredg.'
However, now when I use these two number arrays (if that's what they are) my code returns the error
Error in dcells[[dredging[whichD]]] : subscript out of bounds
I believe this error is referring to the following lines of code:
if(julday>=dstart[whichD] & julday<=dend[whichD] & dredging[whichD]!=0){
whichcells<-which(gridd$inds[gridd$julday==julday] %in% dcells[[ dredging[whichD] ]]) #identify cells where dredging is occurring
}
where:
whichD<-1
julday<-1+day
'dstart=c(1,25,75,100)dend=c(20,60,80,117)`
Here is the full block of code:
for (i in 1:time.steps){
qday <- qday + 1
for (p in 1:pop){
if (is.na(dolphin.q[p,1,i]!=dolphin.q[p,2,i])) {
dolphin.q[p,6,i]<-which.max(c(dolphin.q[p,1,i],dolphin.q[p,2,i]))
}else{
dolphin.q[p,6,i]<-rmulti(c(0.5,0.5))
}
usP<-usage[p,]
if(julday>=dstart[whichD] & julday<=dend[whichD] & dredging[whichD]!=0){
whichcells<-which(gridd$inds[gridd$julday==julday] %in% dcells[[ dredging[whichD] ]])
usP[whichcells]<-0
usP<-usP/sum(usP) #rescale the home range surface to 1
}
I was wondering if anyone could show me what is going wrong? I apologize if this is a very simple mistake I am making, I am a novice learner that has been scouring the internet, manuals, and Stack for days with no luck!
Thanks in advance!
I am trying to fit a list of clickstreams to a Markov chain, using
fitMarkovChain function of library(clickstream).
I've run this piece of code a few months ago and it worked. Now the output is an error:
Error in solve.default(It - Q) : 'a' must be a complex matrix
library(clickstream)
id<-c("123","456","789")
path<-c("Entrance,A,B,A,C,Exit","Entrance,A,C,A,C,B,Exit","Entrance,B,Exit")
clickstreams<-paste(id,path,sep=",")
csf<-tempfile()
writeLines(clickstreams,csf)
cls<-readClickstreams(csf,header=T)
mc<-fitMarkovChain(cls)
Any idea about what's wrong? Thanks in advance.
Upon trying to calculate precision#k, I get an exception. To what follows is the a simple code that reproduces the problem.
First the code defines the variable scope:
initializer = tf.random_uniform_initializer(-0.1, 0.1, seed=1234)
with tf.variable_scope("model", reuse=None, initializer=initializer)
Then it calls those lines:
predictions = tf.Variable(tf.ones([2, 10], tf.int64))
labels = tf.Variable(tf.ones([2, 1], tf.int64))
precision = tf.contrib.metrics.streaming_sparse_precision_at_k(predictions, labels, 5)
tf.initialize_all_variables().run()
(I know this code is meaningless, and tries to calculate the precision given 2 fixed matrices...)
Then I get the following exception:
W tensorflow/core/framework/op_kernel.cc:936] Failed precondition:
Attempting to use uninitialized value
model/precision_at_5/false_positive_at_5 [[Node:
model/precision_at_5/false_positive_at_5/read = IdentityT=DT_DOUBLE,
_class=["loc:#model/precision_at_5/false_positive_at_5"], _device="/job:localhost/replica:0/task:0/gpu:0"]]
The same goes when I tried to invoke streaming_sparse_recall_at_k instead of streaming_sparse_precision_at_k.
The installed version is r0.10 on linux with python 2.7.
Please help... Thanks in advance :)
Unfortunately, tf.initialize_all_variables() doesn't initialize "local" variables (which tend to be internal implementation details for ops like tf.contrib.metrics.streaming_sparse_precision_at_k() and tf.train.string_input_producer(), as opposed to variables used as model weights).
You'll need to add a line to your program that runs tf.initialize_local_variables() before running the evaluation op:
sess.run(tf.initialize_local_variables()) # or `tf.initialize_local_variables().run()`
I'm trying to create new variables from some output from a number of two-piece segmented regression models that I'm running. The code for my new variable is:
initial1=c(fmod$psi[1],fmod2$psi[1], fmod3$psi[1], fmod4$psi[1], fmod5$psi[1], fmod6$psi[1], fmod7$psi[1], fmod8$psi[1], fmod9$psi[1], fmod10$psi[1], fmod11$psi[1],fmod12$psi[1], fmod13$psi[1], fmod14$psi[1], fmod15$psi[1], fmod16$psi[1], fmod17$psi[1], fmod18$psi[1], fmod19$psi[1], fmod20$psi[1], fmod21$psi[1],fmod22$psi[1], fmod23$psi[1], fmod24$psi[1], fmod25$psi[1], fmod26$psi[1], fmod27$psi[1], fmod28$psi[1], fmod29$psi[1], fmod30$psi[1], fmod31$psi[1],fmod32$psi[1], fmod33$psi[1], fmod34$psi[1], fmod35$psi[1], fmod36$psi[1], fmod37$psi[1], fmod38$psi[1], fmod39$psi[1], fmod40$psi[1], fmod41$psi[1],fmod42$psi[1], fmod43$psi[1], fmod44$psi[1], fmod45$psi[1], fmod46$psi[1], fmod47$psi[1], fmod48$psi[1], fmod49$psi[1], fmod50$psi[1], fmod51$psi[1],fmod52$psi[1], fmod53$psi[1], fmod54$psi[1], fmod55$psi[1], fmod56$psi[1], fmod57$psi[1], fmod58$psi[1], fmod59$psi[1], fmod60$psi[1], fmod61$psi[1], fmod62$psi[1], fmod63$psi[1], fmod64$psi[1])
where fmod, fmod2, fmod3, etc. are my regression models. Some of the regression models have errors and do not produce output (because the initial breakpoint estimates are too close to each other). Because of that, when I try to make my 'initial1' variable, I get error messages such as:
Error: object 'fmod12' not found
and the 'initial' variable is not created. I would like these models that don't have output associated with them to be automatically skipped over, or to be replaced with 'NA'. Does anyone know how to do this?
You're creating many different models and giving them numbered names. Why not put them in a list instead?
At model creation time:
for (i in 1:lots) fmod[[i]] <- my_segmented_reg(...)
where my_segmented_reg presumably returns either a model, or NULL or NA.
Then you have a list fmod which you can start using straight away.