1

Trying to do run this code: A <- gnm(wigooutwi ~ -1 + Dref(as.factor(domx$Womaneduc),as.factor(domx$Husbandeduc)),family = binomial, data = domx)

But the error I got is

Error in baseMatrix[, factorAssign == i] <- termTools[[i]] : number of items to replace is not a multiple of replacement length

How can I fix this?

/

This is my whole code:

install.packages("xlsx")

library(readxl)

domx <- read_excel("C:/Users/../Desktop/domx.xlsx")

View(domx)

install.packages("gnm")

require(gnm) set.seed(1) classMobility <- gnm(wigooutwi ~ -1 + Dref(as.function((domx$Womaneduc),as.function(domx$Husbandeduc)),family = binomial, data = domx)

domx$neglectch +domx$argueswhu + domx$refuhsex + domx$burnsfood

/

And the data is 0,1 and 2's.

soetirl13
  • 41
  • 1
  • 6
  • Could you provide a reproducible example? – dmca Nov 16 '18 at 05:52
  • 1
    @dmca yes, I'm following this link: https://www.rdocumentation.org/packages/gnm/versions/1.1-0/topics/Dref under examples. If I only just copy paste it, I get the error that Husbanded, Woman is not a factor. And therefore I `add as.factor` before the variable. – soetirl13 Nov 16 '18 at 06:01
  • Can you provide the code to load the required packages and to create the `domx` data frame? – dmca Nov 16 '18 at 06:10
  • @dmca i don't get it =/ this is my whole code: `install.packages("xlsx") library(readxl) domx <- read_excel("C:/Users/Julia/Desktop/domx.xlsx") View(domx) install.packages("gnm") require(gnm) set.seed(1) classMobility <- gnm(wigooutwi ~ -1 + Dref(as.function((domx$Womaneduc),as.function(domx$Husbandeduc)),family = binomial, data = domx) domx$neglectch +domx$argueswhu + domx$refuhsex + domx$burnsfood ` – soetirl13 Nov 16 '18 at 06:30
  • Please encapsulate data and code in your example. See [here](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) for some tips on how to do just that. Note that formatting (and thus readability) can be improved as well. – Roman Luštrik Nov 16 '18 at 07:28
  • Your data comes from an excel file (`domx.xlsx`) that we can't access. If you can create a data frame using code that we can run on our machines we can recreate what you are doing. – dmca Nov 16 '18 at 07:36
  • @dmca do you mean `Husbandeduc <- c("1,1,0,1,2,2,2,2,2,2,2,1")` `Womaneduc <- c("1,1,0,1,2,1,1,2,2,1,1,2")` `wigooutwi <- c("0,0,0,0,0,0,1,0,0,0,1,1")` ` df<- data.frame(Husbandeduc,Womaneduc,wigooutwi)` `df` – soetirl13 Nov 16 '18 at 12:57
  • @dmca This is the first 12 obsevations. So this is a smaller data frame. Is this what you ment? – soetirl13 Nov 16 '18 at 13:17
  • You need to update the code in your question so that anyone can run it. The way to test this is to start a new R session and run your whole code block from scratch. If you are reproducing the same error then it is more likely that we will be able to do so. [This guide](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) explains the details. – dmca Nov 16 '18 at 16:47

0 Answers0