title: R: Matrix multiplication error - related to GLM
body: <p>I've been trying to build some custom code for Logistic regression (i.e. I cannot use the GLM package for this purpose since - happy to explain why.)</p>
  
  <p>Below is the initial R code to provide the data set I'm working with: </p>
  
  <pre><code>## Load the datasets
  data("titanic_train")
  data("titanic_test")
  
  ## Combining Training and Testing dataset
  complete_data &lt;- rbind(titanic_train, titanic_test)
  
  library(dplyr)
  titanic_test$Survived &lt;- 2
  complete_data &lt;- rbind(titanic_train, titanic_test)
  complete_data$Embarked[complete_data$Embarked==""] &lt;- "S"
  complete_data$Age[is.na(complete_data$Age)] &lt;- 
  median(complete_data$Age,na.rm=T)
  complete_data &lt;- as.data.frame(complete_data)
  titanic_data &lt;- select(complete_data,-c(Cabin, PassengerId, Ticket, 
  Name))
  
  titanic_data &lt;- titanic_data[!titanic_data$Survived == "2", ]
  
  titanic_model &lt;- model &lt;- glm(Survived 
  ~.,family=binomial(link='logit'),data=titanic_data)
  
  
  y &lt;- titanic_data$Survived
  x &lt;- as.data.frame(cbind(rep(1, dim(titanic_data) 
  [1]),titanic_data[,-2]))
  x &lt;- as.matrix(as.numeric(x))
  
  beta &lt;- as.numeric(rep(0, dim(x)[2]))
  beta &lt;- as.matrix(beta)
  </code></pre>
  
  <p>The issue I'm having here is <strong>I would like to compute the matrix product</strong> of <strong>beta</strong> (a px1 matrix) and <strong>x</strong> (a n x p matrix)  </p>
  
  <p>I have tried the following - </p>
  
  <pre><code>beta * x
  x %*% beta
  </code></pre>
  
  <p>However, the above the following errors -  </p>
  
  <blockquote>
    <p>Error in FUN(left, right) : non-numeric argument to binary operator<br>
    Error in x %*% beta : requires numeric/complex matrix/vector arguments</p>
  </blockquote>
  
  <p>I'd imagine this is due to the fact I've got non-numeric fields in the data matrix <strong>x</strong>.<br>
  As a bit of a background, <strong>calculating the linear predictor will allow me to progress with my custom code for fitting a Logistic regression model.</strong><br>
  I would appreciate some help - thank you!</p>