我有一个包含106个不同变量的数据集,其中分别属于两种类型-a和b。例如,这些变量可以是年龄和性别等。我想运行一个线性模型,根据协变量来预测每个个体属于a类型还是b类型。
我使用以下代码读取每个个体的年龄、性别和类型标签:
`data = read.xlsx("spreadsheet.xlsx",2, as.is = TRUE)`
age = data$age
gender = data$gender
type = data$type
其中每个都是以下形式:
age = [28, 30, 19, 23 etc]
gender = [male, male, female, male etc]
type = [a b b b]
然后我尝试使用以下方式设置模型:
model1 = lm(type ~ age + gender)
但是我收到了这个错误消息:
Warning messages:
1: In model.response(mf, "numeric") :
using type="numeric" with a factor response will be ignored
2: In Ops.factor(y, z$residuals) : - not meaningful for factors
我尝试使用以下方式更改type、age和gender的格式:
age = as.numeric(as.character(age))
gender = as.character(gender)
type = as.character(type)
但是这并不起作用!