Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201839

Matrix multiplication. Error in ... %*% beta : non-conformable arguments

$
0
0

I try to find a beta (initial value) to insert in my formula. But it doesn't work to me. I keep getting the following error:

Error in x1 %*% beta : non-conformable arguments

I have used a sample in where I tried to reproduced it, but I did not manage to fix it

The codes of the example:

set.seed(100)
beta <- matrix(c(-10, .1, 20, -.1), 2, 2)
x <- runif(500, 50, 250)
x1 <- cbind(1, x)
xbeta <- x1%*%beta
w <- rbinom(500, 1, .3)
y <- w*rbinom(500, size = 1, prob = (1/(1+exp(-xbeta[, 1]))))+
(1-w)*rbinom(500, size = 1, prob = 
             (1/(1+exp(-xbeta[, 2]))))

My codes:

set.seed(100)
beta <- model.matrix(Churn ~ . , data = data)
x <- runif(500, 50, 250)
x1 <- cbind(1, x)
xbeta <- x1%*%beta
w <- rbinom(500, 1, .3)
y <- w*rbinom(500, size = 1, prob = (1/(1+exp(-xbeta[, 1]))))+
(1-w)*rbinom(500, size = 1, prob = 
             (1/(1+exp(-xbeta[, 2]))))

Below is some information of my dataset

dput(head(beta, 4)) structure(c(1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 34, 2, 45, 0, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 29.85, 56.95, 53.85, 42.3, 29.85, 1889.5, 108.15, 1840.75), .Dim = c(4L, 31L ), .Dimnames = list(c("1", "2", "3", "4"), c("(Intercept)", "genderMale", "SeniorCitizen", "PartnerYes", "DependentsYes", "tenure", "PhoneServiceYes", "MultipleLinesNo phone service", "MultipleLinesYes", "InternetServiceFiber optic", "InternetServiceNo", "OnlineSecurityNo internet service", "OnlineSecurityYes", "OnlineBackupNo internet service", "OnlineBackupYes", "DeviceProtectionNo internet service", "DeviceProtectionYes", "TechSupportNo internet service", "TechSupportYes", "StreamingTVNo internet service", "StreamingTVYes", "StreamingMoviesNo internet service", "StreamingMoviesYes", "ContractOne year", "ContractTwo year", "PaperlessBillingYes", "PaymentMethodCredit card (automatic)", "PaymentMethodElectronic check", "PaymentMethodMailed check", "MonthlyCharges", "TotalCharges")))

If someone knows how I can make my code working it would be really nice. Also, I was wondering what runif and binom values would be good.


Viewing all articles
Browse latest Browse all 201839

Trending Articles