It's a bit hard for me to answer the question. Can you please provide a bit more information about what you have, and what you want to get out? If possible, try to create a reprex, possible using a different dataset?
That said, I can note two things:
A dataframe is defined as an object that has a fixed number of columns and rows (kinda like a matrix) - so when you are trying to create data_mb, it doesn't let you -- since your proposed columns have different lengths (for example -- what should go in the 5th row for column LPD_Name?)
What is mb& Behaviour. This format assumes that mb is a data frame, and it has at least three columns -- Behaviour, activate_behaviou, and passive_behaviour, each with the same number of entries (i.e. the amount of rows in mb). Is this accurate?)
There are 5 possibilities for the Behaviour column - AE, AI, PO, PA, and PI. You want to group AE and AI as "active" and PO, PA, and PI as "passive"
There are 7 possibilities for the Name columns -- Cont 1, Cont 5, Cont 9, LPD 11, LPD 6, LPD 7, LPD 8. You already grouped them into Cont and LPD in the Condition column.
You want to build a regression to predict whether or not Behaviour is active or passive, using Hour, Minute, Condition, and days after birth
If that is correct, I'd suggest the following:
First, create an indicator column about whether behaviour is active -- the output should be 0 or 1
data_mb<within(mb,{active<-active_behaviour})
Days_after_birth Hour Name Minute Behaviour Condition Active
[1,] NA FALSE NA FALSE NA NA FALSE
[2,] NA FALSE NA FALSE NA NA FALSE
[3,] NA FALSE NA FALSE NA NA FALSE
[4,] NA FALSE NA FALSE NA NA FALSE
[5,] NA FALSE NA FALSE NA NA FALSE
[6,] NA FALSE NA FALSE NA NA FALSE
I'm not sure that I run correctly and how to put conditions number.
Correct me pease.
Thank you for your answers, but I'm still having errors message
I two ways:
Using the dplyr
mb$active_behaviour<- mutate (active_behaviour = if_else(Behaviour<-active_behaviour, 1, 0))
Error: condition must be a logical vector, not a character vector
Call rlang::last_error() to see a backtrace
2.Base R
mb$active_behaviour<-as.numeric(mb$Behaviour<-active_behaviour)
Warning message:
NAs introduced by coercion
mb$Cont<-as.numeric(mb$Name<-Cont)
Warning message:
NAs introduced by coercion
mb$LPD<-as.numeric(mb$Name<-LPD)
Warning message:
NAs introduced by coercion
mb$Days_after_birth<-as.numeric(mb$Days_after_birth)
glm1<- glm(data=mb, active_behaviour ~Cont + Days_after_birth,family=binomial)
Error in family$linkfun(mustart) :
Argument mu must be a nonempty numeric vector
The same error with another method of base R
mb$active_behaviour <- ifelse(mb$Behaviour<- active_behaviour, 1, 0)
mb$Cont <- ifelse(mb$Name<- Cont, 1, 0)
mb$LPD <- ifelse(mb$Name<- LPD, 1, 0)
mb$Days_after_birth <- ifelse(mb$Days_after_birth, 1, 0)
glm2<- glm(data=mb, active_behaviour ~Cont + Days_after_birth,family=binomial)
Error in family$linkfun(mustart) :
Argument mu must be a nonempty numeric vector
Try the following two changes -- one applies to the first, dplyr chunk, and the other applies to all 3
dplyr operates on the entire data frame not on the column. This means two things:
the calculation should be assigned directly to mb, not mb$active_behaviour)
the first argument of mutate should be mb -- which can either be simply as mutate(mb, ...) or mb %>% mutate(...)
"<-" does not mean is in, you are looking for %in% . <- means assign something to a variable. Therefore, within a as.numeric(...) or if_else(...), you should never see a <-. For example, if_else(Behaviour %in% active_behaviour, 1, 0) or as.numeric(mb$Behaviour %in% active_behaviour)
Hmm...I'm not 100% sure, but I think I implied the wrong package -- try changing parse_date() to readr::parse_date() -- see if that does anything (or try readr::parse_date(as.character(Days_after_birth), "%m.%d.%Y"))
Finally, I just change data by name each day.
P1<-c("P1")
P2<-c("P2")
P3<-c("P3")
P4<-c("P4")
and than bild a regretion
glm1Cont<-glm(formula = is_active ~ Hour + Minute + is_cont + is_p1, data = mb, family = binomial)
Please tell me, Is it possible to plot a graph with this regression?
For example
While I don't have much experience with GGally, you should make sure that all the things in aes are columns of the mb dataframe -- maybe you want todo is_cont instead of Cont?